Radzen data grid for generic data types

I want to design a common radzen data grid for multiple data types. Which means on the razor page I have common markup for radzen data grid. Record set and column definition bind to the grid dynamically. My problem is with ‘TItme’.

I need something like:
TItem="typeof(data.records[0])"

Datagrid as follows:

<RadzenDataGrid FilterMode="FilterMode.Simple" Data="@data.records" TItem="typeof(data.records[0])" AllowFiltering="@data.allowFiltering" AllowPaging="@data.allowPaging" AllowSorting="@data.allowSorting">       
    <Columns>
        @foreach (var colDef in data.columnDefinitions)
        {
            <RadzenDataGridColumn TItem="typeof(data.records[0])" Property="@colDef.columnProperty" Title="@colDef.columnTitle"  />
        }            
    </Columns>           
</RadzenDataGrid>

The closest thing we can offer is demonstrated in this example. You cannot use typeof to instantiate a generic class.

Hello @korchev,

thank you for prompt response. But on that example, filtering is not working for
FilterMode ="FilterMode.Simple".
is that acceptable?

Hey @anc.dev,

Simple filtering mode definitely works on this demo:


Hi @enchev ,

Sorry my question was wrong about simple filtering. The real problem is I need to do client-side filtering. I no need to call to the DB each time user enters a filter term. This is not working. Any suggestions?

Below is what I’m testing on…

protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                await LoadGridData();
                StateHasChanged();
            }
        }

protected async Task LoadGridData()
        {
            isLoading = true;
            var uri = new Uri("https://services.radzen.com/odata/Northwind/Employees");

            var response = await new HttpClient().SendAsync(new HttpRequestMessage(HttpMethod.Get, uri));

            var result = await response.ReadAsync<ODataServiceResult<IDictionary<string, object>>>();

            data = result.Value.AsODataEnumerable();
            count = result.Count;
            isLoading = false;
        }

................

<RadzenDataGrid AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterMode="FilterMode.Simple"
            AllowPaging="true" PageSize="5" AllowSorting="true" Data="@data" TItem="IDictionary<string, object>"
            IsLoading="@isLoading"
            Count="@count">
        <Columns>
            <RadzenDataGridColumn TItem="IDictionary<string, object>" Property="EmployeeID" Title="EmployeeID" Type="typeof(int)">
                <Template>
                    @context["EmployeeID"]
                </Template>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="IDictionary<string, object>" Property="FirstName" Title="FirstName" Type="typeof(string)">
                <Template>
                    @context["FirstName"]
                </Template>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="IDictionary<string, object>" Property="LastName" Title="LastName" Type="typeof(string)">
                <Template>
                    @context["LastName"]
                </Template>
            </RadzenDataGridColumn>
        </Columns>
    </RadzenDataGrid>

You need to handle LoadData, get the filers from the event argument, filter your data and assign the result to a variable bound to Data property.