Best way to load jqGrid with static data?
We load 10 rows of static开发者_开发百科 data into our jqGrid by creating a JSON string:
var d = "{\"page\":1,\"records\":10,\"total\":1,\"rows\":[" +
"{\"id\":\"1\",\"cell\":[\"\"]}," +
"{\"id\":\"2\",\"cell\":[\"\"]}," +
"{\"id\":\"3\",\"cell\":[\"\"]}," +
"{\"id\":\"4\",\"cell\":[\"\"]}," +
"{\"id\":\"5\",\"cell\":[\"\"]}," +
"{\"id\":\"6\",\"cell\":[\"\"]}," +
"{\"id\":\"7\",\"cell\":[\"\"]}," +
"{\"id\":\"8\",\"cell\":[\"\"]}," +
"{\"id\":\"9\",\"cell\":[\"\"]}," +
"{\"id\":\"10\",\"cell\":[\"\"]}" +
"]}";
And loading that into a grid with datatype:jsonstring
and datastr:d
where our grid has 15 columns and each column is created using a custom formatter.
Is there a better way to do this?
Correspond to the documentation (see description of the data
parameter)
It can replace addRowData method which is slow on relative big data
I don't made any measure myself, but the usage of data
parameter seems me also as one of the most effective ways. It is important how many rows of data you want to add. The parameter datastr
used together with datatype:jsonstring
is relatively old way existing before introducing in the version 3.7 the local paging of data. With respect of the data
parameter you can add large set of pure data, sort it and display the first page of the data. The filling of the first page with the data from the data
parameter will be done with respect of addJSONData
function so the part of work is the same in all cases. Only the filling of data which size is grater as the page size makes the way with the data
parameter more effective.
If you will use data
parameter you should don't forget to define additional id
property in the data array. It can be either the property with default id
name or another name defined in localReader
. If you defined key:true
for one column of the jqGrid, then including of additional id
property is not needed.
Answer is: yes
How? Render a regular table, then use Jqgrid's plugin called "grid.tbltogrid.js". Very useful and simple. Internally it uses "addRowData" method of the jqgrid, but why you need to repeat the written code, right? ;)
精彩评论