You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to load a dynamic CSV and display with a datagrid. I understand that there are complexities when trying to properly bind a dynamic object to datatable however I do not need the data to have a bi-directional binding as I only require the table to be readonly. using the below code I am able to get the datagrid to render properly with all the data before it throws an error.
@inject IJSRuntimeJS
<InputFileid="fileUpload"class="form-control-file"OnChange="@LoadFile" />
@if (data.Count>0)
{
<DataGridTItem="Dictionary<string,object>"Data="@data"Filterable="false"Editable="false"FixedHeader="true"FixedHeaderDataGridHeight="85vh"Virtualize="true"Resizable="true"ResizeMode="TableResizeMode.Header"Hoverable="true"Bordered="true"Striped="true">
<DataGridColumns>
@foreach (varheaderinheaders){
<DataGridColumnTItem="Dictionary<string,object>"Field="@header"Caption="@header"VerticalAlignment="VerticalAlignment.Middle">
<DisplayTemplate>
@(context[header].ToString())
</DisplayTemplate>
</DataGridColumn>
}
</DataGridColumns>
</DataGrid>
}@code{List<string> headers=new();
List<Dictionary<string,object>>data=new();
privateasyncvoidLoadFile(InputFileChangeEventArgse)
{//When the file is loaded it is checked that it is the correct typevartemp=e.File.Name.Substring(e.File.Name.LastIndexOf('.'));
if (awaitJS.InvokeAsync<bool>("checkFile", "fileUpload", ".csv"))
{
data= (awaitHelpers.FileHelper.processCsv(e.File)).ToDictionary();
//A record of the column headers from the uploaded data is kept, this will be used to map those columns to their corresponding salesforce fieldsheaders=data.First().Keys.ToList();
StateHasChanged();
}
}}
This loads and renders all the data properly before throwing the following error.
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'FXZa4UjQaGse8MkeIGHHI0_D7fRzDymDtgULLpXL2Y0'.
System.AggregateException: One or more errors occurred. (Cannot detect the member of System.Collections.Generic.Dictionary`2[System.String,System.Object] (Parameter 'id'))
---> System.ArgumentException: Cannot detect the member of System.Collections.Generic.Dictionary`2[System.String,System.Object] (Parameter 'id')
at Blazorise.DataGrid.Utils.FunctionCompiler.GetSafePropertyOrField(Expression item, String propertyOrFieldName)
at Blazorise.DataGrid.Utils.FunctionCompiler.CreateValueGetter[TItem](String fieldName)
at Blazorise.DataGrid.DataGridColumn`1.<.ctor>b__8_2()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Blazorise.DataGrid._BaseDataGridRow`1.OnAfterRenderAsync(Boolean firstRender)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.NotifyRenderCompletedAsync()
The text was updated successfully, but these errors were encountered:
Hello @Browniee97
We've made it so Field is no longer mandatory. If you do not need that DataGrid handles binding automatically for you, you can just remove it.
In your example, it should work by just removing it.
I am trying to load a dynamic CSV and display with a datagrid. I understand that there are complexities when trying to properly bind a dynamic object to datatable however I do not need the data to have a bi-directional binding as I only require the table to be readonly. using the below code I am able to get the datagrid to render properly with all the data before it throws an error.
This loads and renders all the data properly before throwing the following error.
The text was updated successfully, but these errors were encountered: