当您只有一个选项或者您对布局不满意时,您可以使用更高版本的 Kendo(例如 v2013.1.319)中存在的“ui : func( element ) { }”重载完全自定义过滤器控件
columns : [
{ field: "MyCity", width: 80, title : "City", filterable: customTextFilter },
{ field: "CreatedAt", width: 72, title: "Created", filterable: $scope.customDateFilter }
]
下面是自定义外观的函数:
var customTextFilter =
{
extra : false,
operators : { string : { contains : "Contains"}},
ui : function( element )
{
var parent = element.parent();
while( parent.children().length > 1 )
$(parent.children()[0]).remove( );
parent.prepend( "<input data-bind=\"value:filters[0].value\" class=\"k-textbox\" type=\"text\">" );
}
}
下面是一个有两个 GTE/LTE 格式的日期框的例子:
var customDateFilter =
{
extra : true,
operators : { },
ui : function( element )
{
var parent = element.parent();
while( parent.children().length > 1 )
$(parent.children()[0]).remove( );
parent.prepend(
"On or after:<br/><span class=\"k-widget k-datepicker k-header\">" +
"<span class=\"k-picker-wrap k-state-default\">" +
"<input data-bind=\"value:filters[0].value\" class=\"k-input\" type=\"text\" data-role=\"datepicker\"" +
" style=\"width: 100%\" role=\"textbox\" aria-haspopup=\"true\" aria-expanded=\"false\" aria-disabled=\"false\" " +
" aria-readonly=\"false\" aria-label=\"Choose a date\">" +
"<span unselectable=\"on\" class=\"k-select\" role=\"button\">" +
"<span unselectable=\"on\" class=\"k-icon k-i-calendar\">select</span></span></span></span>" +
"<br/>On or before:<br/>" +
"<span class=\"k-widget k-datepicker k-header\"><span class=\"k-picker-wrap k-state-default\">" +
"<input data-bind=\"value: filters[1].value\" class=\"k-input\" type=\"text\" data-role=\"datepicker\"" +
" style=\"width: 100%\" role=\"textbox\" aria-haspopup=\"true\" aria-expanded=\"false\" " +
" aria-disabled=\"false\" aria-readonly=\"false\" aria-label=\"Choose a date\">" +
"<span unselectable=\"on\" class=\"k-select\" role=\"button\">" +
"<span unselectable=\"on\" class=\"k-icon k-i-calendar\">select</span></span></span></span>"
);
}
};
显然,您可以根据自己的喜好进行模板化,并为日期、布尔值等创建不同的自定义过滤器 - 请注意,对于上面的日期版本,如果您想正确设置运算符,为过滤器 [0] 说出“gte”和“lte” .operator 和 filter[1].operator 你可以像这样在 dataSource.filter 属性上设置它:
dataSource: {
transport :
{
read : function( context )
{
//note that here context.filter.filters has the array
//of applied filters -- you can write a custom RESTful call
//such as angular $http.get( ) or use Kendo native format to
//send filter options to server.
}
},
//filter settings here initialize filter[0], filter[1], etc.
filter : [
{ field : "CreatedAt", operator : "gte" },
{ field : "CreatedAt", operator : "lte" }]
}