gpt4 book ai didi

javascript - 具有自定义过滤器的 Kendo MVVM Grid

转载 作者:可可西里 更新时间:2023-11-01 02:48:17 25 4
gpt4 key购买 nike

我正在使用 MVVM 模式构建一个 Kendo Grid,我想要 2 个自定义过滤器:

  1. 带有 extra = false 和自定义运算符的通用网格过滤器
  2. 带有组合框的自定义列过滤器

非常类似于this Kendo Grid demo .我似乎无法在列上使用 data-filterable 属性或 filterable ui 使其与 MVVM 模式一起工作:

<div data-role="grid"
data-filterable="customGridFilter"
data-columns="[
{ field: 'Id', hidden: 'true' },
{ field: 'Name', filterable: '{ ui: customNameFilter }' },
{ field: 'Value' }
]"
data-bind="source: gridDs">
</div>

我已经 created a JS Fiddle来说明我要做什么。

最佳答案

实际上它只是漏掉了一些点,比如

  • data-filterable="customGridFilter" 应该变成data-filterable="true",
  • 而且在剑道道场中他们使用的是 jQuery 1.9.1 而你的是导致问题的紧凑(边缘)。

更改为 jQuery 1.9.1 后,它工作正常,如下所示

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Untitled</title>

<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.930/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.930/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.930/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2015.3.930/styles/kendo.all.min.css">

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.930/js/angular.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.930/js/jszip.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2015.3.930/js/kendo.all.min.js"></script>
</head>

<body>
<div id="test">
<script>
var customNameFilter = customNameFilter || null;
</script>
<div data-role="grid" data-filterable="true" data-columns="[
{ field: 'Id', hidden: 'true' },
{ field: 'Name', filterable: { ui: customNameFilter } },
{ field: 'Value' }
]" data-bind="source: gridDs"></div>
</div>
<script>
$(document).ready(function() {
customNameFilter = function(e) {
console.log("test")
e.kendoComboBox({
dataSource: {
data: [{
Id: 1,
Name: "Test1"
}, {
Id: 2,
Name: "Test2"
}, {
Id: 3,
Name: "Test3"
}]
},
dataValueField: "Id",
dataTextField: "Name",
filter: "contains"
});
};
var viewModel = kendo.observable({
gridDs: new kendo.data.DataSource({
data: [{
Id: 1,
Name: "Test1",
Value: 3
}, {
Id: 2,
Name: "Test2",
Value: 5
}, {
Id: 3,
Name: "Test3",
Value: 2
}, {
Id: 4,
Name: "Test4",
Value: 7
}]
}),
customGridFilter: {
extra: false,
operators: {
string: {
contains: "Contains",
doesnotcontain: "Does not contain",
eq: "Is equal to",
neq: "Is not equal to",
startswith: "Starts with",
endswith: "Ends with"
}
}
},

});

kendo.bind($('#test'), viewModel);
});

// this doesn't work
//var grid = $('#test').data('kendoGrid');
//grid.options.filterable = customFilter;
</script>
</body>

</html>

关于javascript - 具有自定义过滤器的 Kendo MVVM Grid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33306184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com