I'm implementing an asp.net MVC application that includes a page with nested data Grid. Currently, I'm binding data using a single complex data object and it's loading data correctly.
But the problem is when inner grids have so much data it takes some time to get data from the database and make a data object for all the rows.
What I need to do is get and bind inner grid data when the user expands the selected row.
<div class="panel panel-default">
<div class="panel-body">
<div id="purchase-order-grid"></div>
</div>
</div>
$(document).ready(function () {
$("#purchase-order-grid").kendoGrid({
columns: [
{
field: "PurchaseOrderNumber",
title: "Purchase Order",
width: 80,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
},
{
field: "Store",
title: "Store",
width: 100,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
}
],
detailTemplate: '<div class="second-level-grid"></div>',
detailInit: function (e) {
e.detailRow.find(".second-level-grid").kendoGrid({
dataSource: e.data.Products,
columns: [
{
field: "PartNumber",
title: "Part",
width: 70
},
{
field: "Description",
title: "Description",
width: 150
}
]
})
},
dataSource: {
type: "json",
transport: {
read: {
url: "@Html.Raw(Url.Action("List", "PurchasingPurchaseOrder"))",
type: "POST",
dataType: "json",
data: additionalData
}
}
}
});
}
function additionalData() {
var data = {
StoreId: $('#@Html.IdFor(model => model.StoreId)').val()
};
addAntiForgeryToken(data);
return data;
}
[HttpPost]
public virtual IActionResult List(PurchaseOrderSearchModel model, DataSourceRequest command)
{
int totalCount = 0;
var purchaseOrder = _purchaseOrderService.GetPurchaseOrdersWithSearchOption(model, out totalCount, command.Page - 1, command.PageSize);
return Json(new DataSourceResult { Data = purchaseOrder, Total = totalCount });
}