Radzen fails to set DataGrid's type

Hello @Team,

There has been a frequent bug when setting the type of the DataGrid component in some pages. Here's one example:

protected RadzenGrid<Front.Pages.PersonListComponent> dataGrid;

The type is set correctly if I simply remove the filtering from the Data property:

protected RadzenGrid<Global.Models.Database.Entity> dataGrid;

In both cases I'm manually setting the TItem attribute to Global.Models.Database.Entity, which is in a class inside the same project. Each column also inherits the TItem property as it should:

Any possible workarounds?

I recommend applying the filter when setting the property. Use a Linq expression for a component property will make it evaluate on every StateHasChanged and always rebind the grid. So the solution is to create a page property which has the filter applied e.g.

set the filteredPeople to o ${people.Where(p => some expression)}

1 Like

Worked like a charm! I wasn't aware of this auto rebinding in Blazor.

Of course there's always a but.

Using the old method, the data was filtered immediately after changing the filters:

The recommended solution, however, requires some action in the DataGrid to rebind the filtered values, for example ordering the column:

By looking at the grid source code, I have to call the ApplyFilter method. How can I do that on the filter's DropDown Change event?

Did you try setting the page property which the DataGrid is bound to instead? This is what we do in the Dashboard demo. https://github.com/radzenhq/radzen-blazor/blob/master/RadzenBlazorDemos/Pages/DashboardPage.razor#L252

Yes, I did. Here's the setup (ignore the design errors):

I mean to set it in the Change event of the DropDown. Check the demo that I linked.

1 Like