Reputation: 6597
I have a date column in my jqGrid that I am formatting. In addition, I have a toolbar search. The problem I am having is when I type in data to the search bar to search the formatted date data, it won't search the formatted date, it probably searches the pre-formatted date.
Is there any way to search the formatted date instead, or will I have to try and format it before I insert the data to the jqGrid?
Edit: Some Code
var gridLayout = [
{name: "name", index: "name", width: "250px"},
{name: "state", index: "state", width: "50px", hidden: true},
{name: "stateName", index: "stateName", width: "100px", hidden: true,
sorttype: function(cellValue, rowObj) {
return rowObj.state;
}},
{name: "stateImg", index: "stateImg", width: "50px", align: "center",
sorttype: function(cellValue, rowObj) {
return rowObj.state;
}},
{name: "launchDate", index: "launchDate", width: "150px", sorttype: "date",
formatter: 'date', formatoptions: {srcformat: "ISO8601Long", newformat:"n/j/Y, g:i:s A"}},
{name: "lastWorked", index: "lastWorked", width: "150px",
formatter: 'date', formatoptions: {srcformat: "ISO8601Long", newformat:"n/j/Y, g:i:s A"}}
];
I with the toolbar search above the launchdate/lastworked elements, I am trying to search for a date in the format specified in the "newformat" field, but it does not reply with any data when I do so.
After running a test, it does indeed search with the old format.
Edit:
I found an online example here: http://www.ok-soft-gmbh.com/jqGrid/MarkR.htm
If you enter 10/31/2007 into the date search bar and press enter, nothing appears. But if you type 2007-10-31 and press enter, the row with cell 10/31/2007 does appear in the search results. This is what I'm trying to work around.
Edit: This is jqGrid 4.4.0, jQuery 1.7.2
Upvotes: 1
Views: 7079
Reputation: 221997
jqGrid uses internal function parseDate during local searching/filtering. The implementation is very proprietary. I posted many bug fixes in the function. For example in the last one I suggested some changes to support j
and n
formats which you used. The bug fix is included in the current version 4.4.0 which you use.
Unfortunately the current version (4.4.0) of jqGrid still not supports the format g
which you use. Only h
format is currently supported. To have the format g
supported one can for example include the lines
if(format[k] === 'g') {
tsp.h = parseInt(date[k],10);
}
before the line with if(date[k] !== undefined) {
.
How you can see on the demo the modified code will work:
The fixed version of jquery.jqGrid.src.js
which I used in the demo you can get here.
UPDATED: After writing the answer I posted the following bug report to trirand. I wanted inform all that it's now included in the main code of jqGrid (see here). So the next version of jqGrid (the next after the version 4.4.0) will support the format g
in the date.
Upvotes: 2