hi,
I'm trying to make a reusable component of an ColumnForeignKey, But it gives the following
Error: System.ArgumentNullException: Value cannot be null. (Parameter 'name').
I do not see what i'm doing wrong.
the file 'GC_FK_Relation.razor' contains this code
@using Syncfusion.Blazor.Grids
@inherits GridForeignColumn<Relation>
<CascadingValue Value="@this">
@ChildContent
</CascadingValue>
@code{
[Inject] public IRelationService? RelationService { get; set; }
protected ErrorInfo ErrorInfo { get; set; } = new ErrorInfo();
protected List<Relation> Relations{ get; set; } = new();
async protected override Task OnInitializedAsync()
{
if (RelationService != null) {
var result = await RelationService.GetAll(ErrorInfo);
if (result != null) {
Relations= result.ToList();
}
}
this.ForeignDataSource = Relations;
this.ForeignKeyValue = "RelationName";
this.ForeignKeyField = "RelationId";
await base.OnInitializedAsync();
}
}
I call this from within <gridcolumns> like:
<GC_FK_Relation Field="CustomerId" />
|
[Index.razor]
<SfGrid DataSource="@Orders" Height="315">
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<CustomFKeyColumn Field=@nameof(Order.EmployeeID) ForeignKeyValue="FirstName" ForeignKeyField="EmployeeID" HeaderText="Employee Name - from Custom" Width="150"></CustomFKeyColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid> |
|
[CustomFKeyColumn.razor]
@inject EmployeeService EmployeeService
@inherits GridForeignColumn<EmployeeData>
<CascadingValue Value="@this">
@ChildContent
</CascadingValue>
@code{
private List<EmployeeData> data;
protected override async Task OnInitializedAsync()
{
data = await EmployeeService.GetEmployeeDataAsync();
this.ForeignDataSource = data;
await base.OnInitializedAsync();
}
} |
Hi Rahul,
Thank you for taking the time to sort out the issue.
This
helps me already a lot, but I am a bit disappointed that I still need
to provide the field, foreignkeyvalue and foreignkeyfield from the
parent, for the whole point of making the custom component is that all
this repetitive info for this field does not have to be keyed in every
time i make a grid. Before I was trying to achieve the same thing with a
reusable razor component calling the <GridForeignColumn
Field="....></GridForeignColumn> inside. This was working like a
charm, but the column would not get the right position in the grid.
See: https://www.syncfusion.com/forums/172889/wrong-sequence-of-columns-if-a-column-is-a-razor-component
So now I have to choose between two methods that are both not completely satisfying. If there is a still better way of doing this. I like to know.
Best regards,
Gideon
Hi Rahul,
After extensive checking I cannot get your solution to work. I copied it as close as possible to my situation but I get the exception:
ArgumentNullException: Value cannot be null. (Parameter 'source')
I tried a couple of changes regarding to the parameters like adding the datasource from the parent etc., but nothing made a difference.
I wasted also a long time to find out I was on a version that was not supporting GridForeignColumn at all!!! Now I am on 19.4.0.53
Thank you for your support.
|
[CustomFKeyColumn.razor]
@inject EmployeeService EmployeeService
@inherits GridForeignColumn<EmployeeData>
<CascadingValue Value="@this">
@ChildContent
</CascadingValue>
@code{
private List<EmployeeData> data;
protected override async Task OnInitializedAsync()
{
data = await EmployeeService.GetEmployeeDataAsync();
this.ForeignDataSource = data;
await base.OnInitializedAsync();
}
} |
Hello, I am also struggling with this, and have found that the attached sample you provided actually doesnt work (as-is).
(Maybe it broke during one of the more recent releases)?
Hi James,
As per your suggestion, we have ensured the reported issue by upgrading the attached sample to our latest version by changing the style sheet reference link version and the NuGet package version. We are unable to reproduce the reported issue. Kindly refer to the attachment for your reference.
If you are still facing the reported issue, kindly get back to us with more details about the issue you are facing.
Regards,
Balamurugan Lakshmanan
Attachment: Grid_FK_45144ada.zip