Good afternoon - Does anyone know if GridForeignColumn supports a nested reference beyond 1 level using SfDataManager w/OData?
Example:
Class History is referenced by Monitoring, which is referenced by Asset
Calling History OData endpoint with proper expands returns all data back to the Asset layer, but GridForeignColumn cannot reference it like so:
TValue="Asset" Field= "@nameof(History.Monitoring.AssetID)" ForeignKeyValue="@nameof(Asset.Name)"
Referencing History.MonitoringID works just fine.
The page with Grid loads fine, but no data appears in it. When attempting to sort/filter on the Asset Column, error appears in web console: Value cannot be null. (Parameter 'source')
Thoughts?
Hi leviatekllc,
Greetings from Syncfusion support.
We have checked your query and we would like to inform that in DataGrid we have support for complex column by which we can bind complex data using dot operator. We have documented the topic in the below UG section. Kindly refer the attached screen snip for your reference.
Reference: https://blazor.syncfusion.com/documentation/datagrid/columns#complex-data-binding
Note : Add the expand query using Grid’s Query property as like the above code during complex data binding in Grid using OData service.
So we suggest you to use the Expand method of Query to fetch and bind complex data from odata to grid. You can use as like the below codes.
|
<GridColumns> <GridColumn Field=@nameof(Book.Id) IsPrimaryKey="true" Width="150"></GridColumn> <GridColumn Field="Customer.Name" HeaderText="Name" Width="150"></GridColumn> <GridColumn Field=@nameof(Book.CreditLimit) Width="200" EditType="EditType.NumericEdit"></GridColumn> <GridColumn Field=@nameof(Book.Active) Width="200" EditType="EditType.BooleanEdit"></GridColumn> </GridColumns>
private Query currentQuery = new Query().Select(new List<string> { nameof(Book.Id), nameof(Book.Active), nameof(Book.Customer), nameof(Book.CreditLimit), }).Expand(new List<string> { "Customer" });
|
Kindly get back to us if you have further queries.
Regards,
Monisha
Thanks Monisha for the quick reply, but I am still struggling to get this to work, even just to 1-layer depth.
This is the Url I originally had coded - note the use of nested expands:
/odata/HistoriesOdata?$orderby=ReadingDate%20desc&$expand=Monitoring($expand=Asset($expand=Facility&$expand=AssetType))
#1 - I am not seeing how to use the Query.Expand to achieve this nested expand. All attempts so far have resulted in same-level expand: $expand=Monitoring,Asset,Facility,AssetType
#2 - I could not get your provided example to work by adjusting the Url to Query.Expand:
SfGrid Code Shown here, with the SfDataManager and targeted GridColumn:
Along with the gridQuery code:
The grid renders on the page, but without the Monitoring Column even making an appearance:
Beyond this initial first layer (which, as you see, does work fine with the GridForeignColumn for fields I want to add/edit, I truly need this capability to my other layers, so I could reference items like Asset.Name, Facility.Name, AssetType.Name, etc.
Hi leviatekllc,
Thanks for the update.
We have prepared an sample with nested complex columns using ODataV4 adaptor. Kindly check the attached sample for your reference.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Syncfusion-2014627560.zip
Please get back to us if you have further queries or if you face any difficulties.
Regards,
Monisha