1

I am trying to filter the jqGrid data by date range - that is, by "dateFrom" and "DateTo". Once the date is selected, I have tried to implement:

var dateFilter = {
                groupOp: "AND",
                rules: [
                { "field": "date", "op": "ge", "data": dateFrom },
                { "field": "date", "op": "le", "data": dateTo }
            ]
            }

    jQuery('#' + gridId).jqGrid('setGridParam', {

        postData: {
            filters: JSON.stringify(dateFilter)
        }
    }).trigger("reloadGrid");

But this doesn't seem to work ? I am using ASP.NET MVC but had hoped to do this on the client side by simply filtering the data to between the selected dates ?

Can anyone assist ?

Tom
  • 13
  • 1
  • 1
  • 4

1 Answers1

3

If I understand you correct the old demo from the answer and another demo from the answer will gives you code fragments which you need. Here you could find additionally examples how to construct the filters dynamically.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi Oleg! :) Thanks for the response. How can I do this without the "searchbox" appearing. i.e. I just want to filter the data once the user has selected the date range and the data changes ? The first answer seems to show the searchbox [which I don't want too] ? – Tom Jun 07 '11 at 14:03
  • @Tom: If you set `postData.filters` and then call `.trigger('reloadGrid')` the grid will be refreshed. Is what you mean? Which `datatype` has your grid? Do you use `loadonce:true` parameter? – Oleg Jun 07 '11 at 14:07
  • @Oleg - so I updated my code above. Using JSON, loadonce:true is used yes and now using the above code ? Is this correct or ? – Tom Jun 07 '11 at 14:12
  • @Tom: In general it's correct, but you need to set `search:true` parameter. I recommend that you additionally reset always the page number with `.trigger("reloadGrid",[{page:1}]);` – Oleg Jun 07 '11 at 14:37
  • @Oleg thanks for the help :) Lastly, how do you customise the dateFormat ? i.e. of the Date field - is there a setting to make it appear like dd/mm/yyyy etc ? – Tom Jun 07 '11 at 14:57
  • found it - http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options - thanks :) – Tom Jun 07 '11 at 15:08
  • @Oleg - yep accepted. Searching the data and just trying to ensure that the format is the same ? Do I just use datefmt:'mm-dd-yyyy' within the colModel ? – Tom Jun 07 '11 at 15:23
  • @Tom: The situation could be a little more complexer. So you should describe your situation more exactly. Which date format has your **source** data? What features you use? Do you use `datepicker` for example? – Oleg Jun 07 '11 at 15:28
  • @Tom: To understand more what I mean look at [the demo](http://www.ok-soft-gmbh.com/jqGrid/Localization1.htm) and [this one](http://www.ok-soft-gmbh.com/jqGrid/LocalFormEditingWithContextmenu.htm) – Oleg Jun 07 '11 at 15:47