文檔金喜正規買球>>Kendo UI使用教程-2019>>Kendo UI for jQuery數據管理使用教程:狀態持久性、層次結構
Kendo UI for jQuery數據管理使用教程:狀態持久性、層次結構
Kendo UI for jQuery R1 2020 SP1試用版下載
Kendo UI目前最新提供Kendo UI for jQuery、Kendo UI for Angular、Kendo UI Support for React和Kendo UI Support for Vue四個控件。Kendo UI for jQuery是創建現代Web應用程序的最完整UI庫。
狀態持久性
Grid使您可以保存用戶的自定義設置,并在用戶將來再次登錄后將其還原。
要保留以前應用于其結構的設置,請使用Grid的getOptions和setOptions方法。 這些方法允許您在需要時序列化Grid的當前狀態,并在以后恢復該狀態。
<!DOCTYPE html> <html> <head> <title></title> <link rel="stylesheet" href="styles/kendo.common.min.css" /> <link rel="stylesheet" href="styles/kendo.default.min.css" /> <link rel="stylesheet" href="styles/kendo.default.mobile.min.css" /> <script src="js/jquery.min.js"></script> <script src="js/kendo.all.min.js"></script> </head> <body> <div id="example"> <div class="box wide"> <a href="#" class="k-button" id="save">Save State</a> <a href="#" class="k-button" id="load">Load State</a> </div> <div id="grid"></div> <script> $(document).ready(function () { $("#grid").kendoGrid({ dataSource: { type: "odata", transport: { read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers" }, pageSize: 20 }, height: 550, groupable: true, sortable: true, reorderable: true, resizable: true, columnMenu: true, filterable: { mode: "row" }, pageable: { refresh: true, pageSizes: true, buttonCount: 5 }, columns: [{ field: "ContactName", title: "Contact Name", width: 250, locked: true }, { field: "ContactTitle", title: "Contact Title", width: 350 }, { field: "CompanyName", title: "Company Name", width: 350 }, { field: "Country", width: 450 }] }); var grid = $("#grid").data("kendoGrid"); $("#save").click(function (e) { e.preventDefault(); localStorage["kendo-grid-options"] = kendo.stringify(grid.getOptions()); }); $("#load").click(function (e) { e.preventDefault(); var options = localStorage["kendo-grid-options"]; if (options) { grid.setOptions(JSON.parse(options)); } }); }); </script> </div> </body> </html>
層次結構
Grid通過以分層方式顯示其表數據,提供用于可視化父記錄和子記錄之間關系的選項。
要在Grid中實現層次結構,請連接其detailInit事件并根據父鍵字段值過濾子表中的記錄。
<!DOCTYPE html> <html> <head> <title></title> <link rel="stylesheet" href="styles/kendo.common.min.css" /> <link rel="stylesheet" href="styles/kendo.default.min.css" /> <link rel="stylesheet" href="styles/kendo.default.mobile.min.css" /> <script src="js/jquery.min.js"></script> <script src="js/kendo.all.min.js"></script> </head> <body> <div id="example"> <div id="grid"></div> <script> $(document).ready(function() { var element = $("#grid").kendoGrid({ dataSource: { type: "odata", transport: { read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Employees" }, pageSize: 6, serverPaging: true, serverSorting: true }, height: 600, sortable: true, pageable: true, detailInit: detailInit, dataBound: function() { this.expandRow(this.tbody.find("tr.k-master-row").first()); }, columns: [ { field: "FirstName", title: "First Name", width: "110px" }, { field: "LastName", title: "Last Name", width: "110px" }, { field: "Country", width: "110px" }, { field: "City", width: "110px" }, { field: "Title" } ] }); }); function detailInit(e) { $("<div/>").appendTo(e.detailCell).kendoGrid({ dataSource: { type: "odata", transport: { read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders" }, serverPaging: true, serverSorting: true, serverFiltering: true, pageSize: 10, filter: { field: "EmployeeID", operator: "eq", value: e.data.EmployeeID } }, scrollable: false, sortable: true, pageable: true, columns: [ { field: "OrderID", width: "110px" }, { field: "ShipCountry", title:"Ship Country", width: "110px" }, { field: "ShipAddress", title:"Ship Address" }, { field: "ShipName", title: "Ship Name", width: "300px" } ] }); } </script> </div> </body> </html>
掃描關注慧聚IT微信公眾號,及時獲取最新動態及最新資訊
