Hi,
I have a need to display multiple ColumnLayouts using LoadOnDemand. Currently everything is working as expecting except the Children ColumnLayouts displayed a empty Grid.
GridModel gridModel = this.GetGridModel(ajaxUpdateTarget, 0); GridUIHelper.ApplyLayout(ref gridModel, vm); gridModel.DataSource = resultSet.Result.AsQueryable(); return gridModel.GetData();Thank you
Hello Phong,
Your requirement could be achieved by handling childGridCreating event. This event is fired before child grid is going to be created and allows the developer to override the child grid creation. In this event a reference to the parent row triggering the event could be retrieved. From the row you could get information about any cell that you would like and will help you uniquely identify your record. Afterwards, this data could be sent to the server(via the dataSource option) and there you could filter your data accordingly. For example:
//in Grid.cshtml $(function () { $("#grid-id-test").live("igchildgridcreating", function (evt, ui) { var parentRowId = ui.element.parents("tr[data-container='true']").prev().data("id"), parentGrid = ui.element.parents("table.ui-iggrid-table").data("igGrid"), parentRowData = parentGrid.findRecordByKey(parentRowId); //every cell value could be retrieved using the column key var productNumber = parentRowData.ProductNumber; //afterwards this value could be send to the server via dataSource option ui.options.dataSource += "&productNumber=" + productNumber; }); }); . . . //in HomeController.cs public JsonResult GetChildren(string ajaxUpdateTarget, string path, string layout, string productNumber) { if (ajaxUpdateTarget == "History" && productNumber=”AR-5381”) { //filter your data according to your productNumber and add it to the response WrappedGridResponse response; response = new WrappedGridResponse(histories, null); return Json(response, JsonRequestBehavior.AllowGet); } else { //handle it according to you scenario } }
//in Grid.cshtml
$(function () {
$("#grid-id-test").live("igchildgridcreating", function (evt, ui) {
var parentRowId = ui.element.parents("tr[data-container='true']").prev().data("id"),
parentGrid = ui.element.parents("table.ui-iggrid-table").data("igGrid"),
parentRowData = parentGrid.findRecordByKey(parentRowId);
//every cell value could be retrieved using the column key
var productNumber = parentRowData.ProductNumber;
//afterwards this value could be send to the server via dataSource option
ui.options.dataSource += "&productNumber=" + productNumber;
});
.
//in HomeController.cs
public JsonResult GetChildren(string ajaxUpdateTarget, string path, string layout, string productNumber)
{
if (ajaxUpdateTarget == "History" && productNumber=”AR-5381”)
//filter your data according to your productNumber and add it to the response
WrappedGridResponse response;
response = new WrappedGridResponse(histories, null);
return Json(response, JsonRequestBehavior.AllowGet);
}
else
//handle it according to you scenario
I believe this approach will help you achieve your requirement. However, we have a known issue logged in our internal system regarding firing of the childGridCreating event. This issue is fixed and currently being tested.
I have created a support case with an ID of CAS-154476-Q1J6Y4 for you and I will link it to our Development issue so you will get notification when it is released. You could view this case in your account in the Support Activity page.
Please let me know if you need any further assistance with this matter.
Thank you.
I am need have to solution ASAP.
Thanks again for looking into it.
I am currently looking into this matter for you. I will get back to you soon with more information or questions for you.
Hi Vasya,
The problem is ProductID information is not enough for me to get the Related Information of the Children. This is what I am trying to do:
1. From the expanding row, get the ProductId, ProductName, and other information. I don't want to go to the database to get the Product based on ProductId. This is not efficient because I have many nested Grids per Product.
2. Filter the Children data with (ProductId, ProductName, and other information)
3. Bind the result to the response
Please help. Thank you
I am glad that you find my suggestion helpful.
What I can suggest for achieving your requirement is using GetChildren method. This method parameters will give you enough information to determine which is the current ProductID, respectively which parent row invoked the GetChilden method. Layout parameter contains information about the current layout. Based on these two parameters you could filter your data in order to retrieve only the rows needed for the corresponding child. For example if I am trying to expand first row, Adjustable Race 0, GetChild method will be called with ajaxUpdateTarger="Histories", path: ProductID: 0,layout="Histroies". You could check which layout triggered the event and filter data accordingly and add it to the WrappedGridresponse.
public JsonResult GetChildren(string ajaxUpdateTarget, string path, string layout) { if (ajaxUpdateTarget == "History") { //filter your data according to the path and layout and add filtered data to the response WrappedGridResponse response; response = new WrappedGridResponse(histories, null); return Json(response, JsonRequestBehavior.AllowGet); } else { //filter your data according to the path and layout and add filtered data to the response gridModel.DataSource = something.AsQueryable(); WrappedGridResponse response; response = new WrappedGridResponse(something, null); return Json(response, JsonRequestBehavior.AllowGet); } }
public JsonResult GetChildren(string ajaxUpdateTarget, string path, string layout)
if (ajaxUpdateTarget == "History")
//filter your data according to the path and layout and add filtered data to the response
gridModel.DataSource = something.AsQueryable();
response = new WrappedGridResponse(something, null);
I hope you find this information helpful.