文檔金喜正規買球>>Kendo UI使用教程-2019>>Kendo UI for jQuery數據管理使用教程:Filter概述
Kendo UI for jQuery數據管理使用教程:Filter概述
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庫。
小部件是一個統一的控件,用于篩選具有數據源的數據綁定組件。
Filter的用戶界面對于沒有內置UI進行篩選但需要提供篩選器選項的數據綁定組件很有用,例如ListView,Chart和Scheduler。 您可以添加或刪除用于過濾數據的字段,并為每個字段選擇過濾器的全局邏輯(AND或OR)和過濾器運算符(例如,包含或等于)。您可以通過內置按鈕或API調用應用過濾,還可以選擇名稱,以這些名稱顯示給用戶并本地化過濾器操作符和消息。
初始化Filter
要使用過濾器,請使用一個空的"div"元素,并在初始化腳本中提供其設置。
下面的示例演示如何:
- 將Filter綁定到數據源。
- 在列表視圖中顯示過濾的數據。
- 在字段中使用易于理解的名稱。
- 設置初始過濾器表達式。
注意:
- 您可以使用遠程數據源而不是本地數據數組。 在本示例中,為簡潔起見,使用了本地數組。
- 不需要提供字段,因為過濾器可以從數據源中提取它們。 如果您未在過濾器設置中設置字段,則會向用戶顯示實際的字段名稱,而不是可讀的標簽。如果您在過濾器設置中設置了字段,則它們必須與數據源的架構匹配。
- 不需要提供初始過濾器表達式,此功能對于還原以前的狀態很有用。
<div id="filter"></div><ul id="listView"></ul> <script type="text/x-kendo-template" id="item"> <li> <strong>#= name #</strong>, aged #= age #, is on vacation: #= isOnLeave # </li> </script> <script> $(document).ready(function () { var dataSource = new kendo.data.DataSource({ data: [ { name: "Jane Doe", age: "25", isOnLeave: false }, { name: "John Doe", age: "33", isOnLeave: true }, { name: "John Smith", age: "37", isOnLeave: true }, { name: "Nathan Doe", age: 42, isOnLeave: false } ], schema: { model: { fields: { name: { type: "string" }, age: { type: "number" }, isOnLeave: { type: "boolean" } } } } }); $("#filter").kendoFilter({ dataSource: dataSource, expressionPreview: true, // Shows a text preview of the filter expression. applyButton: true, // Shows the built-in Apply button. fields: [ // Defining the fields is not mandatory. Otherwise, they will be taken from the data source schema. // If you define the fields, their names and types must match the data source definition. { name: "name", type: "string", label: "Name" }, { name: "age", type: "number", label: "Age" }, { name: "isOnLeave", type: "boolean", label: "On Vacation" } ], expression: { // Defining an initial filter expression is not required. logic: "and", filters: [ { field: "age", value: 30, operator: "gte" }, { field: "name", value: "Doe", operator: "contains" } ] } }).data("kendoFilter").applyFilter(); // Chain the method call to immediately apply filtering after the widget initialization because an initial filter is set. $("#listView").kendoListView({ dataSource: dataSource, template: kendo.template($("#item").html()) }); }); </script>
功能和特點
- 設置運算符
- 保持狀態
- 全球化
引用現有實例
要引用現有的Filter實例,請使用jQuery.data()方法。 建立引用后,請使用Filter API來控制其操作。
var filter = $("#theFilter").data("kendoFilter");
掃描關注慧聚IT微信公眾號,及時獲取最新動態及最新資訊
