I'm using Guriddo jqGrid 5.2.1. I've defined a jsonReader
to handle the non-standard format of the data being returned by the URL:
jsonReader : {
root:"payload.rows",
page: "payload.page", // the current page
total: "payload.total", // the total # of pages
records: "payload.records" // the total # of records
},
The grid also has loadonce
set to true
, so that all of the data is loaded once. This makes it possible for me to let the grid handle sorting instead of requesting sorted data from the server. One of the input fields in the rows is a date represented in milliseconds. I defined a beforeProcessing
function to handle converting the date in each row to be a value that can be formatted properly:
beforeProcessing: function (data) {
for(var i = 0; i < data.payload.rows.length; i++) {
var d = new Date(data.payload.rows[i].ihw);
data.payload.rows[i].ihw = d;
}
},
This worked fine when the data is initially retrieved. However, I noticed that beforeProcessing
is called whenever I click on a column to sort, even though loadonce
is set to true
. I can change the code to handle formatting the date using a formatter
like in this post. However, I have other data manipulation needs where, for example, I'd like add a new field to each row that is a concatenation of three other fields in the row. When jsonReader
is used, the incoming data appears to be transformed into the standard jqgrid format, so that the next time beforeProcessing
is executed (upon a sort, for example), the beforeProcessing
code errors because the data is now in a different format than before. Is there an event I can use that only runs once, after the data is initially retrieved from the server? Or do I need to set a JavaScrpt variable in beforeProcessing
that indicates that the data has been processed once, and skip processing in subsequent calls?