Jquery Jqgrid未使用新数据更新
我有jqgrid实现,无法在其中加载数据。我附上代码,请让我知道。我正在从控制器成功检索数据,无法用新数据重新加载jqgridJquery Jqgrid未使用新数据更新,jquery,json,asp.net-mvc,jqgrid,Jquery,Json,Asp.net Mvc,Jqgrid,我有jqgrid实现,无法在其中加载数据。我附上代码,请让我知道。我正在从控制器成功检索数据,无法用新数据重新加载jqgrid $("#btn1").on("click", function() { alert(j + " " + k); var d = { 'firstField': i, 'secondField': j, 'thirdField': k } $.ajax({ type: 'post', url: '/TodoList/
$("#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
});
您正在接收的数据是json,这是Jqgrid所期望的,因此您不应该对数据进行字符串化。将函数修改为
function callme(newone1) {
$grid.jqGrid('clearGridData');
$grid.jqGrid('setGridParam', {
datatype: 'local',
data: newone1.rows // modify this
}).trigger("reloadGrid");
}
旁注:<代码>传统:Trime< /Cord>Ajax选项不需要(您不向控制器发送数组)
,那么也许您应该考虑接受答案。