我在主细节模式下使用jqGrid。当我单击主网格中的一行时,我运行了SelectedRowHandler javascript函数,我想更新细节网格,但它不起作用。
调用选定的行处理程序并调用对该操作的调用,但网格不会更新。
这是js
function SelectedRowHandler(rowId) {
var rowData = this.p.data[this.p._index[rowId]];
$.ajax({
type: "POST",
url: '/Invoice/invoiceitems2',
data: { invoiceId: rowData.Id },
datatype: "json",
success: function (data) {
$("#InvoiceItemsGrid").jqGrid("GridUnload");
var mygrid = $("#InvoiceItemsGrid")[0];
var myjsongrid = eval("(" + data.responseText + ")");
myjsongrid = null;
data = null;
},
viewrecords: true
});
return true;
}
ActionResult是
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult InvoiceItems2(int invoiceId)
{
var response = new JqGridResponse();
var invoiceItems = _invoiceItemRepository.GetMany(p => p.InvoiceId == invoiceId);
foreach (var x in invoiceItems)
{
response.Records.Add(new JqGridRecord(Convert.ToString(x.InvoiceItemId), new InvoiceItemViewModel()
{
Id = x.InvoiceItemId,
PartNo = x.PartNo,
Description =
x.Description,
Quantity = x.Quantity,
Price = x.Price,
Total =
x.Quantity*x.Price
}));
}
return new JqGridJsonResult() {Data = response};
}
我将不胜感激任何帮助。
答案 0 :(得分:1)
尝试此操作而不是ajax调用
jQuery("#your_detail_grid_id").jqGrid('setGridParam',{url:"/Invoice/invoiceitems2?invoiceId="+rowId,page:1}).trigger('reloadGrid');
请参阅jqgrid demo
中的主要详情高级 - >主细节