Cannot add record to an empty datagrid with GridForeignColumn.
Version: 19.2.0.55
The datagrid needs to have a GridForeignColumn where the foreign column is assigned to the grid's model's foreign key. If the grid is empty with no records, pressing the add button will result in the stack trace below appearing on the console.
DataGrid:
<SfGrid TValue="Codes" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" AllowPaging="true">
<GridEvents TValue="Codes"OnActionFailure="@ActionFailure"></GridEvents>
<SfDataManager Url="@(Configuration["HostName"] + "/Codes/GetCodes")"
RemoveUrl="@(Configuration["HostName"] + "/Codes")"
UpdateUrl="@(Configuration["HostName"] + "/Codes")"
InsertUrl="@(Configuration["HostName"] + "/Codes")" Adaptor="Adaptors.WebApiAdaptor"></SfDataManager>
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" />
<GridColumns>
<GridColumn Field=@nameof(Codes.RecordID) HeaderText="RecordID" Visible="false" IsPrimaryKey="true" AllowEditing="false" />
<GridColumn Field=@nameof(Codes.DisplayName) HeaderText="Code Description" EditType="EditType.DefaultEdit" Type="ColumnType.String" />
<GridColumn Field=@nameof(Codes.Value) HeaderText="Code" EditType="EditType.DefaultEdit" />
<GridForeignColumn Field=@nameof(Codes.CodeTypeId) HeaderText="Code Type" TValue="Codes_Type" ForeignKeyField="RecordId" ForeignKeyValue="DisplayName">
<SfDataManager Url="@(Configuration["HostName"] + "/CodeType/GetCodeType")" Adaptor="Adaptors.WebApiAdaptor"></SfDataManager>
</GridForeignColumn>
</GridColumns>
</SfGrid>
Stack Trace:
blazor.webassembly.js:1 Uncaught (in promise) Error: System.ArgumentNullException: Value cannot be null. (Parameter 'source')
at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.Any[Object](IEnumerable`1 source)
at Syncfusion.Blazor.Grids.Internal.RowModelGenerator`1[ConfigData.Models.Codes, ConfigData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].RefreshForeignKeyRow(Row`1 row, Object item)
at Syncfusion.Blazor.Grids.Internal.RowModelGenerator`1[[ ConfigData.Models.Codes , ConfigData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GenerateRow(Object item, Int32 index)
at Syncfusion.Blazor.Grids.Internal.Edit`1[[ ConfigData.Models.Codes , ConfigData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetModelGenerator(codes)
at Syncfusion.Blazor.Grids.Internal.Edit`1.<AddRecord>d__65[[ ConfigData.Models.Codes , ConfigData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext(codes)
at Syncfusion.Blazor.Grids.SfGrid`1.<AddRecord>d__879[[ ConfigData.Models.Codes , ConfigData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext(codes)
at Syncfusion.Blazor.Grids.Internal.GridToolbar`1.<ToolbarClickHandler>d__17[[ ConfigData.Models.Codes , ConfigData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext(codes)
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Syncfusion.Blazor.Navigations.SfToolbar.TriggerClickEvent(MouseEventArgs e, Boolean isPopupElement, Boolean isCloseIcon, Nullable`1 trgParentDataIndex, String id, Nullable`1 tabItemIndex)
at Object.endInvokeDotNetFromJS (blazor.webassembly.js:1:3549)
at Object.Xt [as endInvokeDotNetFromJS] (blazor.webassembly.js:1:63263)
at Object.Gt [as invokeJSFromDotNet] (blazor.webassembly.js:1:62760)
at Object.Ii (dotnet.7.0.11.mkt3lq0pfv.js:5:71974)
at _mono_wasm_invoke_js_blazor (dotnet.7.0.11.mkt3lq0pfv.js:14:103886)
at 00993932:0x1d6b8
at 00993932:0x1cae6
at 00993932:0xe1d6
at 00993932:0xd046
at 00993932:0x1a2379
Hi Jose,
Based on your query, It seems that error in Datagrid with GridForeignColumn
When Adding Records to an Empty Grid. We have prepared a simple sample in
the latest version (24.1.47) and validated it on our end. However, the reported
problem does not occur on our side. Please refer the sample for your
reference.
Sample : https://blazorplayground.syncfusion.com/embed/VZLTDsrnzLPqbAza?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5
If the reported issue still reproduced then kindly share the below details to validate further at our end.
- Please share if we missed any replication procedure in attached sample
- Could you please ensure that , reported issue still occurs in latest version(24.1.47)
- Share a video demonstration of the issue with a detailed explanation. This will greatly assist us in understanding the problem.
- Please provide a simple sample that reproduces the issue with duplicate data or try to modify the above mentioned sample.
The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible.
Regards,
Naveen Palanivel
- 1 Reply
- 2 Participants
-
JO Jose
- Jan 25, 2024 04:40 PM UTC
- Jan 28, 2024 10:03 PM UTC