Reputation: 23
Here issue is filter the grid data(service data) based on datetime picker. I'm unable to provide the service so i am using here hard code data,but my requriment is filter service data based on date and time. here is the jsbin http://jsbin.com/exakic/41/edit
Upvotes: 1
Views: 1432
Reputation: 40897
You placed the parse
function in the grid
definition and not in the datasource
. You also need to provide a format that matches the one being received ("yyyy-MM-dd HH:mm:ss"). Try this:
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;
}
}
I would also do a couple of additional changes:
format
definition in your DateTimePickers
to match the format in the Grid
:Code:
$("#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"
});
blur
event by change
event to make it get fired only if the value of the input field actually changes.Code:
$("#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);
});
Upvotes: 1