3

I am stuck here - last thing to get done before going production.

The date coming from oracle is on the following format: "8/14/2012 10:46:48 AM"

I am using the following on the jqgrid:

{ name: 'CreationDate', index: 'CreationDate', formatter: 'date', formatoptions:    { 'srcformat': 'ISO8601Long', 'newformat': 'm/d/Y - g:i A' }, sorttype: 'date', width: 95, align: 'right', resizable: false },

I have the following displaying on the grid: "08/14/2012 - 10:46AM"

The problem is when I try to use the advanced filter it doesn't work. My guess is because of the time, any suggestions on how to solve this?

UPDATE

Oleg, I copied the code you posted with your changes and still nothing. I am using the advanced filter. Thanks for all your help, I really, really appreciate it. I wish I could send you some beer to Germany :o)

Not working sample

Working sample with full text

nneonneo
  • 171,345
  • 36
  • 312
  • 383
user1409155
  • 31
  • 1
  • 5
  • More info, the json data shows the data as "2012-08-14T10:46:48". If I enter 2012-08-14 on the filter, it filters fine, but if I enter 08/14/201 it doesn't – user1409155 Aug 14 '12 at 16:33

1 Answers1

1

I think the main problem is that you use g format inside of newformat which are not currently supported in jqGrid for the local filtering/searching. You can try to use H format instead. Alternatively you can use the fix which is described in the answer.

UPDATED: The demo shows that one can use Advanced Searching dialog with formatter: 'date', formatoptions: { 'srcformat': 'ISO8601Long', 'newformat': 'm/d/Y - g:i A' } after applying the fix which I referenced. You can just try the demo and input the same data (10/04/2012 - 5:55 PM) which I used on the picture below. You have to see the following results:

enter image description here

UPDATED 2: During preparing of another demo for you I found one more bug in internal parseDate function. The problem is that the current implementation of parseDate function works correct only if the date which are need be parsed contain the same elements as specified the format. For example the date 10/04/2012 will be incorrect parsed using 'm/d/Y - g:i A' format. To fix the bug one can include the line

if(typeof date[k] === "undefined") { continue; }

as the first line of the body of the loop. The fixed version of jquery.jqGrid.src.js you can get here.

In the demo I use multipleSearch: true option of jqGrid searching. As the result one can specify the interval of dates like

10/04/2012 <= x <= 10/05/2012

The corresponding Searching Dialog will look like on the picture below and you will be able to filter by intervals of dates

enter image description here

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Oleg, thanks for the reply but still doesn't work. I changed the format to H { 'srcformat': 'ISO8601Long', 'newformat': 'm/d/Y - H:i A' } but didn't help the filter only works with I type the wat the data is coming on json "2012-08-14". If I tried to implement other answer then I have to type everything, including the time. Any other way you think I would do this? Thanks again. – user1409155 Aug 14 '12 at 21:13
  • Is there anyway to write a custom filter just for this date column? – user1409155 Aug 15 '12 at 14:27
  • @user1409155: Sorry, but I don't see any problem in the filtering of the data after applying the fix which I referenced. I made the demo for you which demonstrate that all works correctly. See **UPDATED** part of my answer. – Oleg Aug 15 '12 at 16:32
  • thanks again Oleg. The problem with the filter is that I have to type the whole thing to search. i.e. I cannot filter all 10/05/2012, it will not return any results. I have to enter 10/05/1012 - 7:10AM. Does that make sense? – user1409155 Aug 16 '12 at 14:49
  • @user1409155: See **UPDATED 2** part of the answer. – Oleg Aug 16 '12 at 16:18
  • @user1409155: You are welcome! You wrote about "Advanced Filter". So I understood you wrong. There are only [Advanced Searching Dialog](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:advanced_searching) or [Toolbar Filter](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:toolbar_searching). So I supposed that you mean "Advanced Searching" before you posed the screenshorts. The searching for the interval of dates is not directly supported in jqGrid. To implement this you can use `beforeSearch` callback of `filterToolbar`, but the implementation would be very tricky. – Oleg Aug 16 '12 at 18:10
  • @user1409155: It you decide to try the way with `beforeSearch` I would recommend you to read [the following my old answer](http://stackoverflow.com/a/8953934/315935). Modifying of the demo from the answer you will be able to implement what you need. In the demo I used the structure of filter which corresponds to `multipleSearch: true, multipleGroup: true` options of the searching and which `filters` structure are described [here](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:advanced_searching#options). – Oleg Aug 16 '12 at 18:15
  • @user1409155: By the way, as I wrote the part "UPDATED 2" of my answer I drunk beer at the same time. I am currently in Swiss in the business trip at one customer. So I wrote some answers at the stackoverflow in Hotel after the work. I am glad that I could help you and it's enough for me to have best wishes from you. – Oleg Aug 16 '12 at 18:19
  • Hey, Oleg. I am still stuck. Sorry man! I am not trying to search interval dates, I am trying to use the Toolbar Filter (sorry I said it wrong before) to match on the date only disregarding the time. The problem I am having is that the filter only works if I enter the date and time as you can see on my screenshot #2, if I enter just the date screenshot #1 it doesn't work. – user1409155 Aug 17 '12 at 14:12