我的问题是:
- 我使用的jqGrid显示本地数据
- 这个数据是从Web服务解析几个部分
- 我得到的对象数组作为数据(可以更改)
- 我尝试添加新的数据部分与addJSONData零件,没有运气
- 我也尝试将jqGrid参数“数据”设置为数据部分的合并数组,没有运气的jqGrid通过JavaScript对象添加本地数据
随着一些trys我得到空行。
使用格式化程序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”:338591,“range”:2,“gps”:“338,591”,...}]工作吗? – GMO 2012-04-18 20:29:02
@GMO:如果您为服务器单独调用Ajax来获取数据,我建议您使用'datatype:“json”'并直接从服务器获取数据。在数据类型为“local”的情况下,可以直接使用[{“id”:338591,“range”:2,“gps”:“338,591”,...}]' – Oleg 2012-04-18 20:31:39