我的问题如下:
-我正在使用jqgrid显示本地数据
-从Web服务中分几部分解析此数据
-我得到一个对象数组作为数据(可以更改)
-我尝试用addJSONData逐个添加新的数据部分,不走运
-我也尝试将jqGrid参数“ data”设置为数据部分的合并数组,没有运气
经过一些尝试,我得到了空行。
使用格式化程序,rowObject可以,但是cellValue为空(未定义)。
似乎colModel和数据结构不“兼容”。
我希望能够将数据分几部分添加到网格中。
这些行应按排序显示。
以下是参数:
{
caption: 'Villes',
data: [],
datatype: 'local',
colNames: ['Actions', 'Distance', 'Coordonnées', 'Nom', 'Joueur', 'Puissance', 'Alliance', 'Diplomatie', 'Brumes', 'Status'],
colModel: [
{name: 'actions', sortable: false, search: false, formatter: Shared.gridRowActions, width: 50},
{name: 'range', index: 'range', width: 60},
{name: 'coords', index: 'gps', sortable: false, search: false, formatter: function( cellValue, options, rowObject ){ return Shared.mapLink(cellValue); }, width: 90},
{name: 'city', index: 'city'},
{name: 'player', index: 'player'},
{name: 'might', index: 'might', align: 'right', defval: 0, formatter: function( cellValue, options, rowObject ){ return Shared.format(cellValue); }, width: 70},
{name: 'guild', index: 'guild'},
{name: 'diplomacy', index: 'diplomacy', formatter: function( cellValue, options, rowObject ){ return Shared.getDiplomacy(cellValue); }, width: 70},
{name: 'mist', index: 'mist', align: 'center', formatter: function( cellValue, options, rowObject ){ return cellValue === 1 ? 'Oui' : ''; }, width: 55},
{name: 'user', index: 'user', formatter: function( cellValue, options, rowObject ){ return Shared.userStatusLink(cellValue); }}
],
pager: '#pager-cities',
loadui: 'disable',
rowNum: 20,
rowList: [20, 50, 100],
sortname: 'range',
sortorder: 'asc',
altRows: true,
autowidth: true,
viewrecords: true,
gridview: true,
multiselect: true,
multiboxonly: true,
multikey: 'shiftKey'
}
然后是将数据添加到网格的代码。
var merged = [];
var $grid = $('#grid);
...
merged = merged.concat(cities);
$grid.jqGrid('setGridParam', {data: merged}).trigger('reloadGrid');
还尝试了:
$grid[0].addJSONData( {page: 0, total: 0, records: cities.length, rows: cities} );
数据数组就是一个例子:
[
{"id":338591,"cell":[2,"338,591","140","15545536","Lord Patrice02200","","0","Patrice02200",0]},
{"id":339591,"cell":[2.24,"339,591","50","16300072","Lord mercedes9pd7e","","0","mercedes9pd7e",0]},
{"id":341591,"cell":[3.61,"341,591","727714","16330552","Lord Torkan","","0","Rizane",0]},
{"id":341592,"cell":[4.24,"341,592","490","10929616","Lord pulpfiction","","0","pietra",0]}
]
我真正需要的唯一东西是能够按部分加载数据的功能,并且在添加每个数据之后对网格数据进行排序显示。
工作寻呼机将是一个奖励。
最佳答案
您的问题是您选择了非常特殊的数据格式。本地数据的默认格式表示是具有命名属性的对象数组。数组项中的其他属性应为id
。您使用其他格式,因此必须添加描述数据格式的localReader参数
The demo
使用与您发布相同的网格。我刚刚添加
localReader: {repeatitems: true}
并删除了所有未发布代码的格式化程序。填充网格的最佳方法是对输入数据使用
data
选项。我添加height: "auto"
只是为了更好地查看网格。所以你会看到