【发布时间】:2013-11-28 09:47:02
【问题描述】:
我想在剑道网格的过滤器中设置用户定义的搜索值。一旦用户打开过滤器,该值就会被放入搜索框中。任何建议将不胜感激。
这与Set default filter for Kendo UI Grid 的问题类似,只是我使用的是 Angular js 并且我想要一个用户定义的字符串过滤器值:
这就是我构建网格的方式。我正在使用 angular js 创建一个具有自定义属性的 div。最值得注意的属性是sg-grid(剑道网格本身)、sg-filterable(设置为 true 表示该网格应该是可过滤的)和sg-predefine-filter(也设置为 true 表示该网格的过滤器应该有一个字符串打开时在搜索框中输入):
-
标记
<div sg-grid sg-data="api/grid/accounts" sg-columns="accountId,name,pricingFrequency,shortName,status" sg-filterable="true" sg-predefine-filter-value="true" </div> -
脚本(此处简化为演示)
angular.module('sgComponents').directive('sgGrid', [ return { restrict: 'AE', scope: { filterable: @sgFilterable, predefineFilterValue: @sgPredefineFilterValue}, template: '<div class="sg-grid">\ <div class="pager-bar">\ <div></div>\ // THE KENDO GRID </div>\ </div>', link: function(scope, element, attrs) { buildGrid(); function buildGrid() { var grid = element.find(':nth-child(2)'); // 2nd DIV IN THE TEMPLATE var gridOptions = buildGridOptions(scope, attrs, grid); grid.kendoGrid(gridOptions); // build the grid }; /** Builds the options for the grid */ function buildGridOptions(scope, attrs, grid) { if (scope.filterable === 'true') { opts.filterable = {}; opts.filterable.operators = {}; opts.filterable.operators.string = {} if (scope.predefineFilterValue === 'true') { // set a pre-defined value if true opts.filterable.operators.string = { eq: 'Is equal to', value:'Test' } } else { // just show the filter option opts.filterable.operators.string = { eq: 'Is equal to' } } } } } }; ]); 这是控制台日志的图像:
结果。如您所见,我的值被添加为另一个过滤器选项。我不要这个,我要它在输入框中作为一个值!
【问题讨论】:
标签: angularjs kendo-ui kendo-grid