custom GridForeignColumn gives an ArgumentNullException

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" />

 


7 Replies

RN Rahul Narayanasamy Syncfusion Team February 18, 2022 03:19 AM UTC

Hi Gideon, 

Greetings from Syncfusion. 

We are currently checking the reported query from our end and we will update the further details within two business days. Until then we appreciate your patience. 

Regards, 
Rahul 



RN Rahul Narayanasamy Syncfusion Team February 23, 2022 04:47 AM UTC

Hi Gideon, 
 
Thanks for your patience. 
 
Based on your shared details, we have checked the reported problem. You need to provide the Field, ForeignKeyValue and ForeignKeyField value from parent component and you need to call await base.OnInitializedAsync() in  the extended Custom Foreign key file like below code snippets. 
 
[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(); 
    } 
} 


Please let us know if you have any concerns. 

Regards 
Rahul 



GI Gideon February 23, 2022 06:04 PM UTC

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



GI Gideon February 23, 2022 09:09 PM UTC

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.



RN Rahul Narayanasamy Syncfusion Team February 25, 2022 04:08 AM UTC

Hi Gideon, 
 
Thanks for the update. 
 
We would let you know that while defining the GridForeginColumn as a custom component, we need to provide the Field, ForeignKeyValue and ForeignKeyField value from parent component. 
 
Query: 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') 
 
We suspect that you are still facing difficulties while implementing the provided solution at your end. We suspect that you are passing the ForeignDataSource also from the parent component. We need to pass only Field, ForeignKeyValue and ForeignKeyField from parent component. The ForeignDataSource can defined in CustomForeignKey column file itself. Can you check the below case from your end? 
 
[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(); 
    } 
} 
 
If you are still facing the problem, then could you please share the below details which will be helpful to validate and provide a better solution. 
 
  • Full Grid code snippets and defined the Custom foreign key column file codes.
  • Reproduce the problem in the provided sample and revert back to us.
 
Regards, 
Rahul  



JM James McWhinney replied to Rahul Narayanasamy December 31, 2022 11:22 PM UTC

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)?



BL Balamurugan Lakshmanan Syncfusion Team January 4, 2023 08:40 AM UTC

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


Loader.
Up arrow icon