2

I use this method to export my data:

$('#list').jqGrid('getRowData')

But now I want the getRowData to return only the data from visible columns.

I hide my columns like so:

$("#list").jqGrid('hideCol',columnName)

Does jqGrid support this out of the box? Or will I need to build something custom?

DisplayName
  • 3,093
  • 5
  • 35
  • 42
jorrebor
  • 2,166
  • 12
  • 48
  • 74

1 Answers1

2

The method getRowData has no option to export only visible data. So if you need to have the data I can suggest you two implementation ways:

  1. You can get all data using getRowData and then remove unneeded properties from every item of resulting data. The call $('#list').jqGrid('getGridParam', 'colModel') get you array of columns of the grid. Every item of colModel array contain hidden property. If the hidden property is true then the corresponding column is non-visible and you can delete name property of the item from all items of array returned by getRowData.
  2. You can define your own modification of getRowData which export only visible data. To do this you need make copy of the source code of getRowData (see here), make modification of the line from
if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn') {

to

if ( nm !== 'cb' && nm !== 'subgrid' && nm !== 'rn' && !$t.p.colModel[i].hidden) {

The resulting method will do what you need.

I described in the answer how you can add new method to jqGrid. So your code can be something like

$.jgrid.extend({
    getVisibleRowData: function(rowid) {
        // here can be the copy of the code of getRowData 
        // starting with the line
        //    var res = {}, resall, getall=false, len, j=0;
        // see https://github.com/tonytomov/jqGrid/blob/v4.5.2/js/grid.base.js#L3027-L3061
        // you need just make the described above
        // modification of one line of the code
    }
});

You can use new method by name: $('#list').jqGrid('getVisibleRowData').

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798