在Kendo UI Grid中,使用列自己的值填充列的筛选器值可以通过自定义筛选器模板来实现。以下是详细步骤和相关概念:
以下是一个示例,展示如何在Kendo UI Grid中使用列自己的值填充列的筛选器值:
<!DOCTYPE html>
<html>
<head>
<title>Kendo UI Grid Custom Filter</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2023.1.117/styles/kendo.common.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2023.1.117/styles/kendo.default.min.css">
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2023.1.117/js/kendo.all.min.js"></script>
</head>
<body>
<div id="grid"></div>
<script>
$(document).ready(function () {
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
},
schema: {
model: {
fields: {
OrderID: { type: "number" },
Freight: { type: "number" },
ShipName: { type: "string" }
}
}
},
pageSize: 20
},
height: 550,
sortable: true,
pageable: true,
filterable: {
extra: false,
operators: {
string: {
contains: "Contains",
eq: "Is equal to",
neq: "Is not equal to",
startswith: "Starts with",
endswith: "Ends with"
},
number: {
eq: "Is equal to",
neq: "Is not equal to",
gte: "Is greater than or equal to",
gt: "Is greater than",
lte: "Is less than or equal to",
lt: "Is less than"
}
}
},
columns: [
{ field: "OrderID", title: "Order ID", width: 120 },
{ field: "Freight", title: "Freight", width: 120 },
{
field: "ShipName",
title: "Ship Name",
width: 200,
filterable: {
ui: function (element) {
element.kendoAutoComplete({
dataSource: {
transport: {
read: function (options) {
var grid = $("#grid").data("kendoGrid");
var field = "ShipName";
var data = grid.dataSource.data().map(function (item) {
return item[field];
});
options.success(data);
}
},
schema: {
data: function (response) {
return response;
}
}
},
placeholder: "Select ship name...",
filter: "contains"
});
}
}
}
]
});
});
</script>
</body>
</html>
ShipName
列中,通过filterable.ui
属性定义了一个自定义的筛选器UI。这里使用了Kendo UI的AutoComplete组件,从Grid的数据源中动态获取ShipName
的值,并将其作为筛选器的选项。dataSource.read()
方法刷新数据源。通过上述方法,可以有效地在Kendo UI Grid中使用列自己的值填充列的筛选器值,并解决相关问题。
没有搜到相关的文章