views:

146

answers:

1

My app populates a jqGrid, over and over again, with the results of many different queries the user may make; the queries take the form: give me title, documentCategory, hits, documentType for all documents where the document contains the word 'x'. The user may make many such (ajax) queries, one after the other: Issue query. Read the list of titles returned by the database. Do some work. Make another such query. And so on and so on.

I create the grid once, and when the ajax database call returns with some data, the grid is first depopulated and then repopulated, like this:

 $("#titles-table").jqGrid('clearGridData');
 .
 .
 .  // loop through the data returned by the ajax database call
      for (var i = 0 ...
      {
        row = ...
        $("#titles-table").jqGrid('addRowData',i, row); 
      }

But now with version 3.7, the grid has a new 'data' property that is supposedly faster than addRowData. The examples demonstrating this new data property show the grid being populated as it is being instantiated (as the colModel is defined, etc etc). But assuming the grid already exists and will be depopulated with a clearGridData call, is there then a way to set the grid's data property to repopulate the grid? Something analogous to clearGridData, like this:

  $(#titles-table).jqGrid('setGridData', data);

I am interested in a faster way to populate the grid. Firefox displays the "script taking too long" message when my grid has 75 rows, but Chrome and Opera and Safari blaze right thru this amount of data instantly.

A: 

According to the jqGrid docs, this option can be changed after the grid is created via setGridParam. For example:

$(#titles-table).jqGrid('setGridParam', data);
Justin Ethier
Thanks, Justin, for pointing me to that page. I am having no success with the setGridParam approach, however. When the data property is set in this way, jqGrid appears to assume that it had initiated an ajax call to fetch the data, and the code hits an undefined eventhandle. The grid is never populated with data.
Tim