Blazor - Custom Grid - Error When Passing DataSource

Hi,

I am building custom grids using the example posted here:  https://blazor.syncfusion.com/documentation/datagrid/how-to/create-custom-grid-component

For the most part, this works well.  However, I am having trouble when passing a data source into the Custom Grid.

Can you please confirm that you can reproduce this error and let me know how I can get around it?

My CustomGrid.razor is defined as follows:

@using Syncfusion.Blazor.Grids
@typeparam TValue
@inherits SfGrid<TValue>

<SfGrid TValue="TValue"
AllowSorting="true" AllowPaging="true"
@attributes="props">
    <GridEditSettings Mode="EditMode.Batch"></GridEditSettings>
    <GridSelectionSettings Mode="SelectionMode.Cell" CellSelectionMode="CellSelectionMode.Box" Type="SelectionType.Multiple"></GridSelectionSettings>
    @ChildContent
</SfGrid>
@code {
    IReadOnlyDictionary<string, object> props { get; set; }
    public override Task SetParametersAsync(ParameterView parameters)
    {
        props = parameters.ToDictionary();
        return base.SetParametersAsync(parameters);
    }
}

CustomGrid.razor.cs

using Syncfusion.Blazor.Grids;
namespace SyncfusionBlazorApp5_CustomGrid.Pages
{
    public partial class CustomGrid<TValue> : SfGrid<TValue>
    {
    }
}


ControlAccountsPage.razor

@page "/ControlAccounts"
@using Microsoft.EntityFrameworkCore
@using ControlAccount = SyncfusionBlazorApp5_CustomGrid.Data.ControlAccount
@using WBS = SyncfusionBlazorApp5_CustomGrid.Data.WBS
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Buttons
@using SyncfusionBlazorApp5_CustomGrid.Data
@inject IDbContextFactory<Context> dbFact

    <SfButton @onclick="RequeryDb" >Requery</SfButton>
    <CustomGrid DataSource="DbItems" TValue="ControlAccount" Height="500px">
        <GridColumns>
            <GridColumn Field=@nameof(ControlAccount.ID)></GridColumn>
            <GridColumn Field=@nameof(ControlAccount.Description)></GridColumn>
            <GridColumn Field=@nameof(ControlAccount.Code)></GridColumn>
            <GridColumn Field=@nameof(ControlAccount.Comments)></GridColumn>
        </GridColumns>
    </CustomGrid>

@code {

    public List<ControlAccount> DbItems { get; set; } = new();

    protected override async Task OnInitializedAsync()
    {
        await RequeryDb();
        await base.OnInitializedAsync();
    }

    public async Task RequeryDb()
    {
        var db = await dbFact.CreateDbContextAsync();
        DbItems = await db.ControlAccounts.OrderBy(x => x.Code).ToListAsync();
    }
}

Error Messsage:

blazor.server.js:1 [2022-09-29T01:54:29.454Z] Error: System.ArgumentNullException: Value cannot be null. (Parameter 'source')
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.Where[TSource](IEnumerable`1 source, Func`2 predicate)
   at Syncfusion.Blazor.Grids.SfGrid`1.PreventFilterQuery(ActionEventArgs`1 args)
   at Syncfusion.Blazor.Grids.SfGrid`1.ModelChanged(ActionEventArgs`1 args, Object additionalArgs)
   at Syncfusion.Blazor.Grids.SfGrid`1.OnParametersSetAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)



Attachment: SyncfusionBlazorApp5_CustomGrid_c10482bd.zip

3 Replies 1 reply marked as answer

SP Sarveswaran Palani Syncfusion Team September 30, 2022 03:36 AM UTC

Hi Greg,


Thanks for contacting Syncfusion support.


We have analyzed your query and fixed similar kind of stack trace error in recent volume release. So please upgrade to our latest version of Syncfusion NuGet package to resolve the reported issue. Please find the Nuget package for latest fixes and features from below.


Nuget : https://www.nuget.org/packages/Syncfusion.Blazor.Grid


Kindly get back to us if you have any further queries

   

Regards,            

Sarveswaran PK


Marked as answer

GW Greg Wruck September 30, 2022 03:40 AM UTC

Thanks, 

I have updated my sample project to 20.3.0.47 and it now works.



SP Sarveswaran Palani Syncfusion Team October 3, 2022 01:23 AM UTC

Hi Greg,

Thanks for an update.

We're happy to hear that your issue has been resolved.

We'll close this ticket, please get back to us if you have any further queries.

Regards,

Sarveswaran PK


Loader.
Up arrow icon