Best way to load jqGrid with static data?

不打扰是莪最后的温柔 提交于 2020-01-25 10:11:09

问题


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?


回答1:


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.




回答2:


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? ;)



来源:https://stackoverflow.com/questions/4315210/best-way-to-load-jqgrid-with-static-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!