Kendo Grid日期列自定义过滤:将日期格式改为MM/DD/YYYY的问题
Kendo Grid列菜单过滤多选列表日期格式修正
要让列菜单里的多选过滤日期列表显示为MM/DD/YYYY格式,你需要在对应列的filterable配置中添加itemTemplate来手动格式化每个选项的日期文本——之前的format属性无法覆盖列菜单多选列表的显示格式。
修改你的列配置如下:
columnMenu: true, filterable: { mode: "menu,row" }, columns: [ { selectable: true, width: "37px", }, { field: "Date", title: "Document Date", width: "200px", template: "#=(Date == null) ? ' ' : kendo.toString(Date, FormatDate().DateFormat + ' h:mm tt') #", filterable: { multi: true, search: true, format: "{0:"+FormatDate().DateFormat+"}", // 新增:格式化列菜单多选列表的日期显示 itemTemplate: function(e) { return e.value ? kendo.toString(e.value, FormatDate().DateFormat) : e.text; }, cell: { template: function (args) { args.element.kendoDatePicker({ format: FormatDate().DateFormat, // 补充GMT格式作为解析备选,避免日期解析异常 parseFormats: [FormatDate().DateFormat, "yyyy-MM-ddTHH:mm:ssZ"] }); } } }, attributes: { style: "overflow-wrap: break-word;" }, sortable: { compare: function (a, b, desc) { if (a.Date < b.Date) { return -1; } else if (a.Date > b.Date) { return 1; } return 0; } } } ]
关键说明:
itemTemplate函数会接收每个过滤选项的参数e,通过kendo.toString将原始日期值转为你需要的格式(由FormatDate().DateFormat定义)。- 单元格过滤的
parseFormats新增GMT格式,确保系统能正确解析原始日期数据,避免过滤功能失效。
内容的提问来源于stack exchange,提问作者Jyothika K
相关产品推荐
相关产品推荐

