2016年10月25日 星期二

Kendo UI Grid 筆記

常用設定


        var grid = $("#mygrid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "/Home/data"
                    }
                }
            },
            columns: [
            { field: "Code", title: "代碼", width: "10%" },
            { field: "Name", title: "名稱", width: "50%" },
            { field: "", width: "40%", template: '<button class="k-button">按鈕一</button>' }
            ],
            height: $(document).height() - 200,
            toolbar: kendo.template($("#template").html()),
            pageable: true,
            selectable: "row",
            sortable: true,
            resizable: true,
            noRecords: true,
            pageable: {
                refresh: true,
                pageSizes: true,
                pageSize: 50,
                buttonCount: 5,
                pageSizes: [5, 10, 20, 25, 50, 100, "all"],
                messages: {
                    itemsPerPage: "每頁列數"
                }
            },
            dataBinding: function () {
                record = (this.dataSource.page() - 1) * this.dataSource.pageSize();
                record = isNaN(record) ? 0 : record;
            },
        }).data("kendoGrid");



<script type="text/x-kendo-template" id="template">
    <span style="position: relative; float: left;">
        <input id="inputtext" type="text" class="k-textbox" />
        <button id="btn" class="k-button" >新增</button>
    </span>
</script>

刷新清單

            grid.dataSource.read();
            grid.refresh();


讀取選擇資料

            var selectInfo = grid.dataItem(grid.select());

設定資料來源

            $.get(url, { id: id }, function (result) {
                grid.dataSource.data(result);
            });

or

        var dataSource = new kendo.data.DataSource({
            type: "json",
            transport: {
                read: {
                    url: "/Home/data",
                    type: "GET",
                    data: {
                        id: function () {
                            return selectInfo.id;
                    }
                }
            },
            schema: {
                model: {
                    fields: {
                        Code: { type: "string" },
                        Name: { type: "string" },
                    }
                }
            },
        });


        $("#mygrid").data("kendoGrid").dataSource.data(dataSource.data());

or

            var dataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: "/Home/data",
                        complete: function (e) {
                            mygrid.dataSource.data(e.responseJSON);
                        }
                    }
                }
            });

            dataSource.read();

沒有留言:

張貼留言

預測2031/1/1可能 TWCA 憑證 IOS會出現不信任

緣由: TWCA CYBER Root CA 有兩張、兩個效期 (2030、2047年到期) 推測TWCA 預計 2030年12月會停用: TWCA CYBER Root CA (2030 年到期) TWCA Global Root CA 改用啟用: TWCA CYBER ...