gpt4 book ai didi

javascript - 带日期时间选择器的 KendoGrid 过滤器无法正常工作?

转载 作者:行者123 更新时间:2023-11-28 02:23:16 26 4
gpt4 key购买 nike

这里的问题是根据日期时间选择器过滤网格数据(服务数据)。 我无法提供服务,所以我在这里使用硬编码数据,但我的要求是根据日期和时间过滤服务数据。这是 jsbin http://jsbin.com/exakic/41/edit

最佳答案

您将parse 函数放置在grid 定义中,而不是datasource 中。您还需要提供与收到的格式相匹配的格式(“yyyy-MM-dd HH:mm:ss”)。试试这个:

dataSource: {
data : [
{ FirstName: "Joe", LastName: "Smith", dob: "2013-02-18 19:54:13"},
{ FirstName: "Jane", LastName: "Smith", dob: "2013-02-18 20:55:14" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-02-18 21:56:15" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-02-18 22:57:16" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-02-19 20:55:20" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-02-24 20:56:14" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-02-26 20:57:14" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-02-28 20:42:14" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-03-22 11:55:14" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-03-27 20:55:14" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-04-18 20:55:14" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-04-23 20:55:14" },
{ FirstName: "Jane", LastName: "Smith", dob: "2013-04-24 20:55:14" }
],
schema: {
data: function (data) {
$.each(data, function (i, val) {
val.dob = kendo.parseDate(val.dob, "yyyy-MM-dd HH:mm:ss");
});
return data;
}
}

我还会做一些额外的更改:

  • DateTimePickers 中包含 format 定义,以匹配 Grid 中的格式:

代码:

$("#datetimepicker").kendoDateTimePicker({
showSecond: true,
dateFormat: "dd-MM-yy",
timeFormat: "HH:mm:ss",
format : "dd-MM-yy HH:mm:ss"
});

$("#datetimepicker1").kendoDateTimePicker({
showSecond: true,
dateFormat: "dd-MM-yy",
timeFormat: "HH:mm:ss",
format : "dd-MM-yy HH:mm:ss"
});
  • 通过 change 事件更改 blur 事件,使其仅在输入字段的值实际发生变化时触发。

代码:

$("#datetimepicker, #datetimepicker1").on("change", function () {
var mindate = $('#datetimepicker').data("kendoDateTimePicker").value();
var maxdate = $('#datetimepicker1').data("kendoDateTimePicker").value();
var condition = {
logic : "and",
filters: [
]
};
if (mindate !== null) {
condition.filters.push({ field: "dob", operator: "ge", value: mindate });
}
if (maxdate !== null) {
condition.filters.push({ field: "dob", operator: "le", value: maxdate });
}
result.dataSource.filter(condition);
});

关于javascript - 带日期时间选择器的 KendoGrid 过滤器无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15337764/

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