Declined
Last Updated: 04 May 2021 08:27 by ADMIN
Lark
Created on: 03 May 2021 13:49
Category: Grid
Type: Bug Report
0
Error when grouping by column

I am having problems with grouping in TelerikGrid.

When I drag the column into the header for grouping, I get an error ArgumentNullException: Value cannot be null, apparently,  somewhere in TelerikGrid.SetProcessedGroups.

Test code:
@page "/test"

<div>
    <TelerikGrid @ref="grid" Data="@GridData" @bind-Page="Page" PageSize="PageSize"
                 Pageable="true" Sortable="true" Groupable="true"
                 FilterMode="Telerik.Blazor.GridFilterMode.FilterMenu" 
                 ShowColumnMenu="true"
                 TotalCount="@TotalRowCount"
                 SelectionMode="GridSelectionMode.Single"
                 OnRead=@ReadData>
        <GridAggregates>
            <GridAggregate Field=@nameof(TestData.Name) Aggregate="@GridAggregateType.Count" />
            <GridAggregate Field=@nameof(TestData.Surname) Aggregate="@GridAggregateType.Count" />
            <GridAggregate Field=@nameof(TestData.Department) Aggregate="@GridAggregateType.Count" />
        </GridAggregates>
        <GridColumns>
            <GridColumn Field="@(nameof(TestData.Name))" FieldType="typeof(string)" Editable="false" Groupable="true" ShowColumnMenu="false" />
            <GridColumn Field="@(nameof(TestData.Surname))" FieldType="typeof(string)" Editable="false" Groupable="true" ShowColumnMenu="false" />
            <GridColumn Field="@(nameof(TestData.Department))" FieldType="typeof(string)" Editable="false" Groupable="true" ShowColumnMenu="false" />
            <GridCommandColumn Width="60px" Lockable="false" ShowColumnMenu="true">
                <GridCommandButton Command="View" Icon="information" ShowInEdit="false" OnClick="@ViewItem"></GridCommandButton>
            </GridCommandColumn>
        </GridColumns>
    </TelerikGrid>
</div>


@code {

    protected TelerikGrid<TestData> grid;
    protected List<TestData> GridData { get; set; }
    public int TotalRowCount { get; set; } = 0;
    public int Page { get; set; } = 1;
    public int PageSize { get; set; } = 10;

    protected async Task ReadData(GridReadEventArgs args)
    {
        await LoadData();
    }

    protected async Task LoadData()
    {
        GridData = await GetSampleData();
        TotalRowCount = 100;
    }

    protected async Task<List<TestData>> GetSampleData()
    {
        List<TestData> results = new List<TestData>();

        results.Add(new TestData { Name = "Name1", Surname = "Surname1", Department = "Department1" });
        results.Add(new TestData { Name = "Name2", Surname = "Surname2", Department = "Department1" });
        results.Add(new TestData { Name = "Name3", Surname = "Surname3", Department = "Department1" });
        results.Add(new TestData { Name = "Name4", Surname = "Surname4", Department = "Department1" });
        results.Add(new TestData { Name = "Name5", Surname = "Surname5", Department = "Department2" });
        results.Add(new TestData { Name = "Name6", Surname = "Surname6", Department = "Department2" });
        results.Add(new TestData { Name = "Name7", Surname = "Surname7", Department = "Department2" });
        results.Add(new TestData { Name = "Name8", Surname = "Surname8", Department = "Department3" });
        results.Add(new TestData { Name = "Name9", Surname = "Surname9", Department = "Department3" });
        results.Add(new TestData { Name = "Name10", Surname = "Surname10", Department = "Department4" });

        await Task.Delay(1000); //simulate loading delay ...

        return results;
    }

    protected void ViewItem(GridCommandEventArgs args)
    {
        //navigate to edit view ...
    }

    public class TestData
    {
        public string Name { get; set; }
        public string Surname { get; set; }
        public string Department { get; set; }
    }
}

I am getting the following error:

 

This happens in Chrome and Edge, in Webassembly and Server-side blazor.

Am I doing something wrong?

 

Thanks for the help!

3 comments
ADMIN
Marin Bratanov
Posted on: 04 May 2021 08:27

Glad to see you moving forward, Lark.

I have to mark this as "Declined" because it was not a bug in the component itself, but a configuration issue, though.

If you have further questions on the matter, you can open a support ticket.

--Marin

Lark
Posted on: 04 May 2021 06:54

Hi Martin,

Thank you for the quick response.

Yes, that was my problem, grid needs to be bound to List<object> instead of List<TestData>. Also, I used the Telerik.DataSource.Extensions to shape the data into the correct form, something like this:

protected async Task ReadData(GridReadEventArgs args)
{
        Telerik.DataSource.DataSourceResult result = (await GetSampleData()).ToDataSourceResult(args.Request);
        GridData = result.Data.Cast<object>().ToList();
        TotalRowCount = 100;
}

 

I see that grouping is a bit different when using OnRead, which is logical. I will check the additional git resources and DataSource Extensions to get it working properly on my actual case.

Thanks for the help.

Best regards

ADMIN
Marin Bratanov
Posted on: 03 May 2021 16:49

Hi Lark,

Could you try first making sure that the OnRead event is used with grouping as described in the documentation - see the "Grouping with OnRead" section here - the grid must be bound to an IEnumerable<object> in this case and you will give it a different collection of data in OnRead depending on whether there are groups or not.

You can easily check if that missing bit is the reason for the problem by removing OnRead and TotalCount, and just giving all the Data to the grid directly - if that works, then the missing grouping setup is the problem.

Give this a try and let me know how it goes.

Regards,
Marin Bratanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.