我正在使用kendo ui网格,它对所有日期列都有自定义过滤器。我使用自定义日期过滤器,因为我想在过滤时以“yyyy-MM-dd”格式发送日期。我的网格完全在服务器端运行,用于分页和过滤。
以下是我用于日期栏的MVC中的剑道代码 -
columns.Bound(p => p.CreatedOn).Title("Created On").Width("5%").Format("{0:dd/MM/yyyy}").Filterable(filterable => filterable
.Extra(false).UI("CreatedOnFilter"));
这是我使用的脚本 -
function CreatedOnFilter(e) {
e.kendoDatePicker({
format: "dd/MM/yyyy",
change: function () {
debugger;
var ds = $("#InvoiceGrid").data().kendoGrid.dataSource;
var nd = new Date(this.value());
var day = ("0" + nd.getDate()).slice(-2);
var mnth = ("0" + (nd.getMonth() + 1)).slice(-2);
var formattedDate = [nd.getFullYear(), mnth, day].join("-");
var curr_filters;
if(ds.filter() != undefined){
curr_filters = ds.filter().filters;
var new_filter = {
"filters": [
{
"field": "CreatedOn",
"operator": "contains",///Here is where I want operator as selected by user.
"value": formattedDate
}
]
};
curr_filters.push(new_filter);
}
else{
var new_filter = {
"filters": [
{
"field": "CreatedOn",
"operator": "contains",///Here is where I want operator as selected by user.
"value": formattedDate
}
]
};
curr_filters = new_filter;
}
ds.filter(curr_filters);
this.element.closest("form").data().kendoPopup.close();
// kendo.ui.progress($('#divInvoiceList'), false);
}
});
}
如上面的代码脚本所示。在操作员中,我希望它由用户选择。
任何帮助都将受到高度赞赏。
答案 0 :(得分:1)
我在columns
{
field : "ReceivedDate",
title : "Date Received",
template : "#= kendo.toString(kendo.parseDate(ReceivedDate, 'yyyy-MM-dd'), 'MM/dd/yyyy') #",
filterable : {
cell : {
showOperators : false,
operator : "eq",
template : function(args) {
args.element.kendoDatePicker({
format : "MM/dd/yyyy"
});
}
}
}
},
template
用于更改从服务器收到的格式。