complex data with List or ExpandoObject inside
I make multicultural site for web-shop with localization engine inside it. Almost each table with content has child table with localized texts. For example:

public class BlogTheme
{
[Key]
public int Id { get; set; }
[Required]
public string Key { get; set; }
public string Name { get; set; }
public List<BlogThemeCulture> BlogThemeCultures { get; }
}
public class BlogThemeCulture
{
[Required]
public int Id { get; set; }
[ForeignKey("Id")]
public BlogTheme BlogTheme { get; set; }
[Required]
[MaxLength(2)]
public string CultureId { get; set; }
[ForeignKey("CultureId")]
public Culture Culture { get; set; }
public string Name { get; set; }
}
I use Data Grids to edit main table together with culture values child table depending on culture which is allowed to user. To make it I should transform parent table and include child data. I tried to do it creating DataTable and ExpandoObject.
Reading your https://blazor.syncfusion.com/documentation/datagrid/columns/ I found receipt to use complex data binding. I decided to try it creating childe ExpandoObject inside parent table.
I added property to parent table:
[NotMapped]
public ExpandoObject Names { get; set; }
I created parent table with ExpandoObject included:
IEnumerable<BlogTheme> DataSource = await Db.BlogThemes.AsNoTracking().Include(c => c.BlogThemeCultures).OrderBy(r => r.Key).ToListAsync().ConfigureAwait(false);
foreach (BlogTheme item in DataSource)
{
item.Names = new ExpandoObject();
foreach (string culture in ServerStorage.InterpreterCultures)
{
item.Names.AddProperty(culture, item.BlogThemeCultures.Where(r => r.CultureId == culture).FirstOrDefault()?.Name);
}
}
And I tried to use it in Grid:
<SfGrid @ref="Grid" TValue="BlogTheme" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel", "Search", "ColumnChooser" })"
AllowSelection="true" AllowSorting="true" AllowFiltering="true" AllowPaging="true" AllowMultiSorting="true" AllowReordering="true" AllowResizing="true"
AllowTextWrap="true" EnableAutoFill="true" AllowExcelExport="true"
ShowColumnChooser="true"
ContextMenuItems="@(new List<object>() { "AutoFit", "AutoFitAll", "SortAscending", "SortDescending", "Copy", "Edit", "Delete",
"Save", "Cancel", "ExcelExport", "CsvExport", "FirstPage", "PrevPage", "LastPage", "NextPage"})"
AllowGrouping="false" AllowPdfExport="false">
<GridPageSettings PageSizes="true" />
<GridTextWrapSettings WrapMode="WrapMode.Content" />
<GridSelectionSettings Mode="Syncfusion.Blazor.Grids.SelectionMode.Row" Type="SelectionType.Multiple" />
<GridEvents TValue="BlogTheme" OnActionFailure="ActionFailure" OnActionComplete="ActionComplete" OnActionBegin="ActionBegin" DataBound="OnDataBound" />
@if (IsInitialRender)
{
<SfDataManager AdaptorInstance="@typeof(BlogThemeCRUD)" Adaptor="Adaptors.CustomAdaptor" />
}
<GridColumns>
<GridColumn Field="@nameof(BlogTheme.Id)" IsPrimaryKey="true" Visible="false" Type="ColumnType.Number" ShowInColumnChooser="false" />
<GridColumn Field="@nameof(BlogTheme.Key)" HeaderText="@(StringLocalizer["Key"])" Type="ColumnType.String" AllowEditing="@AllowAll" ShowInColumnChooser="false"/>
<GridColumn Field="@nameof(BlogTheme.Name)" HeaderText="@(StringLocalizer["Name"])" Type="ColumnType.String" AllowEditing="true" ShowInColumnChooser="false"/>
@foreach (Culture culture in ServerStorage.AllCultures)
{
if (ServerStorage.InterpreterCultures.Contains(culture.Id))
{
<GridColumn Field="@($"Names.{culture.Id}")" HeaderText="@culture.Name" Type="ColumnType.String">
<Template>
@(((context as BlogTheme).Names as IDictionary<string, object>)[culture.Id])
</Template>
</GridColumn>
}
}
<GridColumn Width="26px" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Center" ShowInColumnChooser="false">
<GridCommandColumns>
<GridCommandColumn ButtonOption="@(new CommandButtonOptions() { IconCss = "icon-new-tab", CssClass = "e-icon-button" })" Title="@(StringLocalizer["Show Theme Blog"])" />
</GridCommandColumns>
</GridColumn>
</GridColumns>
<GridSearchSettings IgnoreAccent="true" IgnoreCase="true" Operator="Operator.Contains" />
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Menu" ShowFilterBarStatus="true" EnableCaseSensitivity="false" IgnoreAccent="true" Mode="FilterBarMode.Immediate" />
<GridSortSettings>
<GridSortColumns>
<GridSortColumn Field="@nameof(BlogTheme.Key)" Direction="SortDirection.Ascending" />
</GridSortColumns>
</GridSortSettings>
<GridEditSettings Mode="EditMode.Normal" AllowAdding="@AllowAll" AllowDeleting="@AllowAll" AllowEditing="true"
AllowNextRowEdit="true" AllowEditOnDblClick="true" ShowDeleteConfirmDialog="true" />
</SfGrid>
The picture with result is included. I think something goes wrong with field binding <GridColumn Field="@($"Names.{culture.Id}")"...
Could you check my solution and offer any help with this mistake or any alternative decision to add lists, dictionaries or expandoobjects as complex data to grid?
SIGN IN To post a reply.
4 Replies
VN
Vignesh Natarajan
Syncfusion Team
May 14, 2020 09:53 AM UTC
Hi Stanislav,
Thanks for contacting Syncfusion support.
Query: “Could you check my solution and offer any help with this mistake or any alternative decision to add lists, dictionaries or expandoobjects as complex data to grid?”
From your query we understood that you want to render Grid with complex properties as ExpandoObject or dictionaries with edit operations. We have tried to prepare a sample as per your code example. (i.e) by converting the child properties to ExpandoObject to parent grid model class property. We are not able to reproduce the reported issue (exception and spinner issues) at our end. But we have done some modification in your code. So kindly refer the below sample for your reference
Kindly share the following details to validate the reported issue at our end.
- Share details about your Column generated in a loop.
- If possible share the issue reproducible sample or try to reproduce the reported issue in provided sample.
- Share your Syncfusion Nuget package version.
Regards,
Vignesh Natarajan
SG
Stanislav Gordenko
May 14, 2020 12:07 PM UTC
Thank you very much for this help.
I tried your sample and found that filter and sorting do not work for inner ExpandoObject fields. Search do not work too. Have you receipt to make them work? If not, for me will be simpler to convert my data to flat ExpandoObject.
One more comment not for this theme - I found that TreeGrid do not work with Expando.
VN
Vignesh Natarajan
Syncfusion Team
May 15, 2020 09:49 AM UTC
Hi Stanislav,
Query: “If not, for me will be simpler to convert my data to flat ExpandoObject.”
Yes. We have support to perform DataOperation and CRUD operations by binding the ExpandoObject data directly to Grid using DataSource property. So kindly make your datasource a flat ExpandoObject to overcome the reported issue.
Or you can bind the child table data in a separate Grid using Hierarchical structure. (i.e.) binding the Culture List in a separate Grid data. Refer our UG documentation and online demo for your reference
Kindly get back to us if you have further queries.
Regards,
Vignesh Natarajan
Vignesh Natarajan
VN
Vignesh Natarajan
Syncfusion Team
May 15, 2020 12:08 PM UTC
Hi Stanislav,
Query: “Tree Grid do not work with Expando”
Currently we do not have support for using ExpandoObject in Tree Grid. Thank you for the taking the time to report the issue and helping us improve our product.
We will mark this as feature request and provide support for ExpandoObject in Tree Grid. The improvement will be rolled out in our 2020 Volume 2 SP1 release which is expected to be rolled out in the middle of August 2020
You can track the current status of your request, review the resolution timeline and contact us for any further inquiries through this link,
Note: To view the above feedback, kindly login into your account.
If you have further queries, please get back to us.
Regards,
Vignesh Natarajan
SIGN IN To post a reply.
- 4 Replies
- 2 Participants
-
SG Stanislav Gordenko
- May 13, 2020 09:15 AM UTC
- May 15, 2020 12:08 PM UTC