我有jqgrid实现,我无法加载数据。我附上代码,请告诉我。我成功地从控制器检索数据,无法使用新数据重新加载jqgrid。
$("#btn1").on("click", function() {
alert(j + " " + k);
var d = { 'firstField': i, 'secondField': j, 'thirdField': k }
$.ajax({
type: 'post',
url: '/TodoList/searchdata',
traditional: true,
dataType: "json",
data: d,
success: function(data) {
callme(data);
}
})
});
function callme(newone1) {
var my = JSON.stringify(newone1.rows);
alert(my);
/*
Json showing in this alert is
[{"accntname":"BSNL","BU":"BCS","salesop":50000,"isdormant":true},
{"accntname":"TATA","BU":"HPSD","salesop":50000,"isdormant":false}]
*/
$grid.jqGrid('clearGridData');
$grid.jqGrid('setGridParam', {
datatype: 'local',
data: my
}).trigger("reloadGrid");
}
我试图用新数据重新加载Jqgrid:
var mydata = [];
$grid.jqGrid({
datatype: "local",
data: mydata,
colModel: [
{ name: "accntname", align: "center", title: false, width: 400, resizable: false, sortable: false },
{ name: "BU", width: 125 },
{ name: "salesop", align: "center", width: 125, sorttype: "date" },
{ name: "isdormant", align: "center", width: 125, sorttype: "date" }
],
caption: "Viz Test",
pager: '#pager',
search: true,
multiselect: true
});
答案 0 :(得分:1)
您收到的数据是json,这是Jqgrid所期望的,因为您不应该对数据进行字符串化。将功能修改为
function callme(newone1) {
$grid.jqGrid('clearGridData');
$grid.jqGrid('setGridParam', {
datatype: 'local',
data: newone1.rows // modify this
}).trigger("reloadGrid");
}
旁注:不需要traditional: true
ajax选项(您不向控制器发送数组)