English 中文(简体)
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.

最佳回答

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
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签