Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving original row data from jqGrid

It is possible to use the getRowData method to retrieve the current of a cell but this retrieves the current cell content rather than the original data before it went through the formatter.

How do I retrieve the original content before the formatting transformations are applied? FYI I am populating the table using JSON.

like image 730
DaveJ Avatar asked Nov 24 '09 07:11

DaveJ


People also ask

How do I select rows in jqGrid?

In order to select the rows based on a data externally using a button, you can use the selectRows method within the click event of the button.

What is rowNum in jqGrid?

jqGrid exposes a property rowNum where you can set the number of rows to display for each page.

How do I delete a row in jqGrid?

jqxGrid('getrowid', selectedrowindex); var commit = $("#jqxgrid"). jqxGrid('deleterow', id); $("#popupWindow"). jqxWindow('hide'); } }); $("#cancel"). click(function () { $("#popupWindow").


1 Answers

I had to dig through the documentation a bit to come up with the solution, to see it in its original context go here: jqGrid Data Manipulation, specifially the section near the end titled "User Data".

First, modify your jsonReader implementation as follows:

 jsonReader: {
      root: 'Data',
      page: 'Page',
      total: 'Total',
      records: 'Records',
      userdata : 'Data',
      repeatitems: false,
      id: 'Id'
 }

Note the userdata option set to the same as root 'Data'

In my case I needed to retrieve the original row data when the user selected a row. I implemented this as follows:

 onSelectRow: function(rowid) {
                    processRow(rowid);
                }

To retrieve the data within the process row method I have the following:

var rowData = $("#resultGrid").getGridParam('userData')[rowId - 1];

Where #resultGrid is a reference to my jqGrid.

This will then return the original data bound to that row before any formatting was applied.

A couple of points to note:

  1. In my case the grid is paged so the result set is never greater than 10 items therefore the 'userdata' wont grow too large
  2. Sorting is performed server side so that index rowId will always return the correct value from 'userData'
  3. While 'userdata' as referenced as an option on jsonReader is all lower case, to retrieve it using getGridParam you need to reference it as 'userData'
like image 172
R Bremner Avatar answered Nov 03 '22 19:11

R Bremner