对列排序后,某些列中的数据丢失
Losing data in some columns after sorting a column
我有一个网页,它在jqGrid中填充了一个JSON对象(版本4.6.0)。JSON对象是从java控制器返回的。我如何初始化网格以及如何填充JSON对象如下所示。
问题是,每当单击列标题时,我都会丢失以下列中的数据:组织、部门和标题。所谓"丢失数据",我的意思是这些列中的数据由于某种原因而消失。这些列恰好是一个嵌套的JSON对象。我在这里错过了什么?谢谢
这是从服务器返回的JSON字符串。
[
{"id":51,"displayName":"John Doe",
"currentExperience": {"id":26,"orgName":"compnay A","deptName":"MIS","title":"senior software engineer"}},
{"id":52,"displayName":"Jane Doe",
"currentExperience": {"id":29,"orgName":"compnay B","deptName":"MIS","title":"software engineer"}}
]
function initializeGrid($grid, $pager, caption)
{
$grid.jqGrid({
datatype: "local",
colNames: ["VipId", "ExpId", "Name", "organization", "department", "title"],
colModel: [
{ name: "id", hidden: true },
{ name: "currentExperience.id", hidden: true },
{ name: "displayName", width: 100, sortable:true },
{ name: "currentExperience.orgName", width: 100, sortable:true },
{ name: "currentExperience.deptName", width: 100, sortable:true },
{ name: "currentExperience.title", width: 100, sortable:true }
],
pager: $pager,
rowNum: 10,
rowList: [10, 20, 30],
sortname: "id",
sortorder: "asc",
viewrecords: true,
gridview: true,
autoencode: true,
caption: caption,
multiselect: true,
width: 450,
hidegrid: false
});
}
function wireClickEventForSearchVipsButton($form)
{
$(document).on("click", "#btnSearchVips", function(event){
event.preventDefault();
var dataMap = composeSearchVipParameters($form);
<c:url var="link" value="/protected/vips/lookup" />
$.ajax({
url: '${link}',
type: 'GET',
dataType: 'json',
accepts: {
text: "application/json"
},
data: dataMap,
error: function() {
alert('an error occurred');
},
success: function(response) {
// this is how I populate response from the server
if (response) {
$grid = $('#gridAvailableVips');
if ($grid) {
$grid.jqGrid("clearGridData");
for(var i=0;i<=response.length;i++) {
$grid.jqGrid('addRowData',i+1,response[i]);
}
}
}
else {
}
}
}); // end of $.ajax()
}); // end of $(document).on()
}
谢谢,奥列格。当使用以下方法时,问题就消失了。
function initializeGrid($grid, $pager, caption, json)
{
$grid.jqGrid({
datastr: json,
datatype: "jsonstring",
colNames: ["VipId", "ExpId", "Name", "organization", "department", "title"],
colModel: [
{ name: "id", hidden: true },
{ name: "currentExperience.id", hidden: true },
{ name: "displayName", width: 100, sortable:true },
{ name: "currentExperience.orgName", width: 100, sortable:true },
{ name: "currentExperience.deptName", width: 100, sortable:true },
{ name: "currentExperience.title", width: 100, sortable:true }
],
pager: $pager,
rowNum: 10,
rowList: [10, 20, 30],
sortname: "id",
sortorder: "asc",
viewrecords: true,
gridview: true,
autoencode: true,
caption: caption,
multiselect: true,
width: 450,
hidegrid: false
});
}
function wireClickEventForSearchVipsButton($form)
{
$(document).on("click", "#btnSearchVips", function(event){
event.preventDefault();
var dataMap = composeSearchVipParameters($form);
<c:url var="link" value="/protected/vips/lookup" />
$.ajax({
url: '${link}',
type: 'GET',
dataType: 'json',
accepts: {
text: "application/json"
},
data: dataMap,
error: function() {
alert('an error occurred');
},
success: function(response) {
// this is how I populate response from the server
if (response) {
$grid = $('#gridAvailableVips');
if ($grid) {
$grid.jqGrid('GridUnload');
initializeGrid($('#gridAvailableVips'), $pagerAvailableVips, 'Available Vips', response);
}
}
else {
}
}
}); // end of $.ajax()
}); // end of $(document).on()
}
相关文章:
- 对角度数据表中括号内的数字进行排序
- 对损坏的子行进行排序的数据表
- 数据表排序但对行进行分组
- 角度未排序数据
- 数据表通过分析一列的值对其进行排序
- 排序数据表
- 对d3堆叠条形图的数据进行排序
- 如何对JQuery Handlebar生成的数据进行排序
- 数组数据排序类似mysql查询
- 使用JQuery对子表数据排序
- 数据排序应该在客户端还是服务器上完成
- a不同列列表的未定义或空引用的数据排序错误
- 日历数据排序 json 树
- 如何在ng-repeat中使用嵌套对象将数据排序为angular js中的JSON数据
- 使用knockout.js与json数据排序列表
- 如何突出显示页面上数据排序类型的菜单项
- dojox.grid.EnhancedGrid中的数据排序
- 在循环值时对JSON数据排序
- 帮助将DIV中的属性数据排序捕获为数组?Jquery/Javascript
- 如何从属性创建数组'数据排序'使用显示的所有分区的Jquery