0

I have custom button to filer the jqgrid. Onpage load grid gives me 100 records. If I export to excel I got 100 records correctly. Then I filter the jqgrid and grid shows me 10 records. But if I export to excel I got 100 records which I got previously.

Below is my code for filter.

$("#grid").jqGrid('setGridParam', {
    search: true,
    postData: {filters: filter},
    sortname: 'statusCode',
    sortorder: 'asc'
});

$("#grid").setGridParam({page:1}).trigger("reloadGrid");
var gridData = $("#grid").jqGrid('getGridParam','data');

In gridData I got 100 object each time irrespective of any filter. I need only records to be export which are displayed in grid after filtration.

Please suggest solution how I can get 10 records from grid.

Oleg
  • 220,925
  • 34
  • 403
  • 798

1 Answers1

0

If you use free jqGrid then you can get the value of new lastSelectedData parameter instead of the value of data parameter. See the first demo at the end of the readme. The most new features are described in the readme or in wiki.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks Oleg . I am trying below code. $("#grid").jqGrid('setGridParam', { search: true, postData: {filters: filter}, sortname: 'statusCode', sortorder: 'asc' }); $("#grid").setGridParam({page:1}).trigger("reloadGrid"); var gridData = $("#grid").jqGrid('getGridParam','lastSelectedData'); But still I am not getting expected result – Mohan Thakare May 06 '15 at 13:38
  • @MohanThakare: You are welcome! Are you sure that you use `datatype: "local"` or the grid have `loadonce: true` and you make **local** filtering of data? In general if the problem do exist you can provide the demo which reproduce the problem. Having the demo I can quickly find the reason in your code of to find the bug in free jqGrid and to fix it. Do you tried [the demo](http://www.ok-soft-gmbh.com/jqGrid/OK/GetFilteredData.htm)? One can set any filter and then click "Show filterd and sorted data (Ids and Client name)" button. You will see all the filtered and sorted data. – Oleg May 06 '15 at 14:01
  • My data type is datatype: 'json' and loadonce: true. I can not change data type. I will try some demo and share it. – Mohan Thakare May 07 '15 at 05:32
  • @MohanThakare: You can create JSFiddle demo for example. The demo http://jsfiddle.net/OlegKi/78m7jdaz/3/ shows how to use Echo service of JSFiddle to create the demo with `datatype: "json"` and `loadonce: true`. The `serverResponse` posted to the server as `postData: {json: JSON.stringify(serverResponse)}` informs Echo service which data should be returned. You can modify the demo, save it and send me the URL. – Oleg May 07 '15 at 05:37
  • @MohanThakare: You can use the latest free jqGrid code (see "External Resources" on the left side). See [the wiki](https://github.com/free-jqgrid/jqGrid/wiki/Access-free-jqGrid-from-different-CDNs#access-githib-code-from-rawgit) – Oleg May 07 '15 at 05:40
  • Still not able to resolve the issue. My basic problem is getting the filtered data from jqgrid in json format. – Mohan Thakare May 07 '15 at 09:18
  • One more thing is there. Please confirm. jqgrid does not have export facility? – Mohan Thakare May 07 '15 at 09:19
  • @MohanThakare: jqGrid is pure JavaScript (jQuery plugin) solution. So one can't implement clean and browser independent export in Excel, Pdf and so on. One needs generate **binary data** for such export. One should just send information about the ids of filtered data to the server and the server should generate the exported binary files with the items. [The answer](http://stackoverflow.com/a/13957161/315935) and [this one](http://stackoverflow.com/a/9349688/315935) described my point of view to the problem. – Oleg May 07 '15 at 09:51
  • I have raised separate question . url is http://stackoverflow.com/questions/30098034/how-to-get-jqgrid-filtered-data-in-json-format – Mohan Thakare May 07 '15 at 10:14