Hello,
I have a grid and the data I receive is in string, even for my 2 date columns. I was able to change them in the preferred Date format, but I can't seem to get the filter and sorting working.
I tried to change the datatype of the columns to datetime, but that was unsuccesfullI
I'm now looking for some help to create a custom filter (and sort) so that I can sort and filter my date columns the correct way.
It's a pretty complicated solution, but here's some of the code were I load my grid:
function
loadGrid(userGridSettings) {
var
gridSettings = {
selectable:
"multiple row"
,
sortable:
true
,
filterable:
true
,
pageable: {
refresh:
true
,
pageSizes: [10, 20, 50, 100],
buttonCount: 5
},
resizable:
true
,
columnMenu:
true
,
toolbar: kendo.template($(
"#searchgrid-toolbar"
).html()),
editable:
"popup"
,
reorderable:
true
,
columnHide: saveState,
columnShow: saveState,
columnResize: saveState,
columnReorder: saveState,
columns: [{
field:
"IsSelected"
,
title:
null
,
sortable:
false
,
filterable:
false
,
width: 25,
menu:
false
,
reorderable:
false
}, {
field:
"BatchName"
,
title:
"Batchnaam"
,
filterable: { multi:
true
}
}, {
field:
"RequesterPartyRequired"
,
title:
"Kabelsel."
,
filterable: { multi:
true
}
}, {
field:
"StartDate"
,
title:
"Plandatum start"
,
type:
"date"
,
format:
"{0: dd-MM-yyyy}"
,
filterable: {
ui:
function
(element) {
element.kendoDatePicker({
format:
'{0: dd-MM-yyyy}'
})
},
multi:
false
}
}, {
field:
"EndDate"
,
title:
"Plandatum eind"
,
type:
"date"
,
format:
"{0: dd-MM-yyyy}"
,
filterable: {
ui:
function
(element) {
element.kendoDatePicker({
format:
'{0: dd-MM-yyyy}'
})
},
multi:
false
}
}, {
field:
"ID"
,
title:
" "
,
filterable:
false
,
sortable:
false
,
width: 25,
menu:
false
,
reorderable:
false
}]
};
var
customFields = [{
field:
"IsSelected"
,
template:
"<input type='checkbox' class='checkbox' #= IsSelected !== undefined && IsSelected ? checked='checked' : '' # />"
,
headerTemplate:
"<input type='checkbox' id='checkAll' />"
},
{
field:
"StartDate"
,
filterable: {
ui:
function
(element) {
element.kendoDatePicker({
format:
'{0: d-M-yyyy}'
})
},
operators: {
string: {
eq:
"Is gelijk aan"
,
neq:
"Is niet gelijk aan"
}
},
multi:
false
},
format:
'{0: d-M-yyyy}'
},
{
field:
"EndDate"
,
filterable: {
ui:
function
(element) {
element.kendoDatePicker({
format:
'{0: d-M-yyyy}'
})
},
operators: {
string: {
eq:
"Is gelijk aan"
,
neq:
"Is niet gelijk aan"
}
},
multi:
false
,
},
format:
'{0: d-M-yyyy}'
},
{
field:
"ID"
,
template:
"#=actionTemplate(data)#"
}];
if
(userGridSettings !== undefined && userGridSettings !==
""
&& userGridSettings !==
null
&& JSON.stringify(userGridSettings) !==
"{}"
) {
gridSettings.columns = userGridSettings;
}
$.each(customFields,
function
(customFieldIndex, customField) {
$.each(gridSettings.columns,
function
(columnIndex, column) {
if
(column.field == customField.field) {
if
(customField.sortable) {
column.sortable = customField.sortable;
}
if
(customField.template) {
column.template = customField.template;
}
if
(customField.headerTemplate) {
column.headerTemplate = customField.headerTemplate;
}
if
(customField.filterable) {
column.filterable = customField.filterable;
}
}
});
});
searchGrid = $(
"#searchGrid"
).kendoGrid(gridSettings).data(
"kendoGrid"
);
searchGrid.thead.find(
"[data-field=IsSelected]>.k-header-column-menu"
).remove();
searchGrid.thead.find(
"[data-field=ID]>.k-header-column-menu"
).remove();
}