I am now using jqGrid(version: jqGrid 4.14.1-pre, free jqGrid), and would like to have a search toolbar with a datepicker. When I click the textbox, the datepicker successfully pops up and it updates the textbox with the date I choose. However, it does not filter the data.
What I really wanted was sopt:["le"] but failed. For checking purpose, I tried the "eq" too. But in both cases, all the data rows disappear.
I did set the
loadonce:true
and tried
$('#list')[0].triggerToolbar();
Since I did use older version of jqGrid, I updated the latest version in GitHub and tried but still failed.
{label: 'LockedDate', name: 'LockedDate', index: 'LockedDate', sorttype: 'date', clearSearch: true,
sortable: true,
resizable: false,
hidden: false,
search: true,
formatter: 'date',
formatoptions: {srcformat: 'm/d/Y h:i:s A', newformat: 'm/d/Y h:i:s A'},
searchrules: {date: true},
searchoptions: {
sopt: ["le"],
dataInit: function (element) {
$(element).datepicker({
dateFormat: 'mm/dd/yy',
changeYear: true,
changeMonth: true,
showButtonPanel: true,
onSelect: function () {
$(this).keydown();
$('#list')[0].triggerToolbar();
},
onChange: function () {
$('#list')[0].triggerToolbar(); }
})
}
}
}
As I remeber rightly, I saw Oleg's answers on stackoverflow (sorry, lost the link) talking about the datetime parsing problem in older version. Is my date format the cause?
Since other search toolbar works well, I don't think this is the problem of pager or grid itself. Could anyone please help me where I set the datepicker wrong??
Thank you! :)
I'm not sure whether this jqGrid code is needed, but just in case I will put:
$('#list').jqGrid({
url: '/LockedObjects/GetLockedObjects',
datatype: "json",
contentType: "application/json; charset-utf-8",
mtype: 'GET',
colModel: [
{label: 'LockedBy', name: 'LockedBy',index: 'LockedBy', sorttype: 'text', clearSearch: true,},
{
label: 'LockedDate', name: 'LockedDate', index: 'LockedDate', sorttype:'date', clearSearch: true,
sortable: true,
resizable: false,
hidden: false,
search: true,
formatter: 'date',
formatoptions: {srcformat: 'm/d/Y h:i:s A', newformat: 'm/d/Y h:i:s A'},
searchrules: {date: true},
searchoptions: {sopt: ["le"],
dataInit: function (element) {
$(element).datepicker({
dateFormat: 'mm/dd/yy',
changeYear: true,
changeMonth: true,
showButtonPanel: true,
onSelect: function () {
$(this).keydown();
$('#list')[0].triggerToolbar();
},
onChange: function () { $('#tbLockedPartiesHistory')[0].triggerToolbar(); }
})
}
}
}],
rowNum: 20,
rowList: [20, 30, 50],
sortName: 'LockedDate',
ignoreCase: true,
viewrecords: true,
sortOrder: 'asc',
loadonce: true,
multiselect: true,
jsonReader: {
repeatitems: false,
root: 'rows',
page: 'page',
total: 'total'
},
height: 'auto',
pager: '#listPager',
loadError: function (xhr, status, error) {
console.log(xhr);
console.log(status);
console.log(error);
}
});
$('#list').jqGrid('filterToolbar', {searchOnEnter: false, ignoreCase: true, searchOperators:true,defaultSearch: 'cn' });
$('#list').jqGrid('navGrid', '#listPager', {edit: false,
add: false,
del: false,
refresh: true
});
};