用静态数据加载jqGrid的最佳方法? [英] Best way to load jqGrid with static data?
问题描述
我们通过创建JSON字符串将10行静态数据加载到jqGrid中:
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\":[\"\"]}" +
"]}";
并将其加载到具有datatype:jsonstring
和datastr:d
的网格中,其中我们的网格有15列,每列都是使用自定义格式程序创建的.
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.
有更好的方法吗?
推荐答案
Correspond to the documentation (see description of the data
parameter)
它可以代替addRowData方法 相对大数据的速度慢
It can replace addRowData method which is slow on relative big data
我自己没有进行任何测量,但是使用data
参数似乎也是最有效的方法之一.要添加多少行数据很重要.与datatype:jsonstring
一起使用的参数datastr
是相对较旧的方式,在3.7版中引入本地数据分页之前.关于data
参数,您可以添加大组纯数据,对其进行排序并显示数据的第一页.对于addJSONData
函数,将使用来自data
参数的数据填充第一页,因此在所有情况下,工作部分都是相同的.仅填充大小随页面大小而变化的数据才能使使用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.
如果要使用data
参数,则不要忘记在数据数组中定义其他id
属性.它可以是具有默认id
名称的属性,也可以是localReader
中定义的其他名称.如果为jqGrid的一列定义了key:true
,则不需要包含其他id
属性.
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.
这篇关于用静态数据加载jqGrid的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!