I am using jqGrid in a master detail mode. When I click on a row in the master grid I run the SelectedRowHandler javascript function which I want to update the details grid but its not working.
The selected row handler is called and the call to the action is called but the grid does not update.
Here is the 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;
}
The ActionResult is
[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};
}
I would appreciate any help.
Try this instead of your ajax call
See the Master Detail in jqgrid demo
Advanced -> Master Detail