Datagrid from a list of custom objects


#1

we can not associate a property from the RowExpand event to a datagrid in the template, do we have a best practice to succeed? the list is called up by Invoke custom method


#2

Hi Francesco,

Do you want to have master/detail hierarchy like this article? You can call for example a custom method on RowExpand and pass a parameter from the row data using ${event} argument of the RowExpand to populate the child grid. For example ${event.CustomerID}.

Best Regards,
Vladimir


#3


but the list is not directly connected to the model, I tried to set a property but on the date of the datagrid I can not manage the various fields on the columns


#4

If the child schema is not directly related to the parent schema you can add still DataGrid columns manually however you have to add properties since they will not be available in the intellisense. For example if you want to display hierarchically Customers and Order Details by customer (not directly related):

public IActionResult OrderDetailsByCustomer(string CustomerID)
{
    var context = (NorthwindContext)HttpContext.RequestServices.GetService(typeof(NorthwindContext));

    return Json(context.OrderDetails.Include("Order")
        .Where(i => i.Order.CustomerID == CustomerID)
        .Select(i => new { OrderID = i.OrderID, ProductID = i.ProductID }),
        new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() });
}


#5

thank you so much, now I can easily map a DataGrid


#6

How can I now reload the datagrid after an add or an edit?


#7

If you execute load() method of the grid you will force loadData event to be raised. For example: this.grid0.load()


#8

I can't recover grid2.load () only this.grid0.load(); in a datagrid template, how do I get it?


#9

You want to reload the child grid? You can execute the code that is used to retrieve the data on row expand.