gpt4 book ai didi

kendo-ui - 是否有任何解决方案可以匹配 Kendo 日期选择器值和网格日期列值

转载 作者:行者123 更新时间:2023-12-04 05:03:45 24 4
gpt4 key购买 nike

我有一个需要选择到和从日期,以便日期应该在网格中匹配并显示结果。但是带有日期的网格列包含日期+时间。所以我的问题是可以忽略时间并只读日期进出日期选择器并匹配网格中的值。

$("#datepicker").kendoDatePicker({
dateFormat: "dd-mm-yy",
format : "dd-MM-yy "});


$("#datepicker1").kendoDatePicker({
dateFormat: "dd-mm-yy",
format : "dd-MM-yy "});


var result=$("#grid").kendoGrid({
filterable: true,


columns: [
{ field: "FirstName", title: "First Name" },
{ field: "LastName", title: "Last Name" },
{ field: "dob", title: "DOB" , format: "{0:dd-MM-yy 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-05-30 21:56:15" },
{ FirstName: "Jane", LastName: "Smith" ,dob:"2013-05-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-03-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;
}
}

}
}).data("kendoGrid");


$("#datepicker, #datepicker1").on("change", function (){
var mindate = $('#datepicker').data("kendoDatePicker").value();
var maxdate = $('#datepicker1').data("kendoDatePicker").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);
});

这是我更新的 fiddle Kendo grid filter with to and from dates

最佳答案

定义一个附加的列,它的日期没有时间,并使用此列进行过滤。

这可以在您的 data 中完成功能:

data: function (data) {
$.each(data, function (i, val) {
val.dob2 = kendo.parseDate(val.dob, "yyyy-MM-dd");
val.dob = kendo.parseDate(val.dob, "yyyy-MM-dd HH:mm:ss");
});
return data;
}

和过滤部分:
$("#datepicker, #datepicker1").on("change", function (){
var mindate = $('#datepicker').data("kendoDatePicker").value();
var maxdate = $('#datepicker1').data("kendoDatePicker").value();
var condition = {
logic : "and",
filters: [
]
};
if (mindate !== null) {
condition.filters.push({ field: "dob2", operator: "ge", value: mindate });
}
if (maxdate !== null) {
condition.filters.push({ field: "dob2", operator: "le", value: maxdate });
}
result.dataSource.filter(condition);
});

第二个选项是将过滤条件定义为:
if (mindate !== null) {
condition.filters.push({ field: "dob", operator: "ge", value: new Date(mindate) });
}
if (maxdate !== null) {
condition.filters.push({ field: "dob", operator: "le", value: new Date(maxdate) });
}

我们添加一个 new Date(...)为日期添加时间。

注意:就您进行客户端过滤而言,这是有效的。如果你在做服务器端过滤,服务器中的查询应该很容易改变来处理这个问题。

关于kendo-ui - 是否有任何解决方案可以匹配 Kendo 日期选择器值和网格日期列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15785203/

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