Completed
Last Updated: 27 Apr 2020 10:59 by ADMIN
Release 2.13.0
inno
Created on: 15 Apr 2020 13:55
Category: Grid
Type: Bug Report
1
Getting error on Hiding and showing a grid columns dynamically in SelectedItemsChanged on version 2.10.0

Reproducible

<TelerikButton OnClick="@(_ => _Splited = !_Splited)">Toggle columns - works fine</TelerikButton>
<br />Select a single row to see the error

<TelerikGrid Data="@GridData"
             Height="480px" RowHeight="40" PageSize="100" SelectionMode="@GridSelectionMode.Multiple"
             Sortable="true" FilterMode="@GridFilterMode.FilterMenu"
             SelectedItemsChanged="@((IEnumerable<Order> objectList) => OnSelect(objectList))"
             OnRead=@ReadOrders
             Pageable="true"
             Resizable="true"
             TotalCount=@TotalOrders>
    <GridColumns>
        <GridCheckboxColumn SelectAll="@ShowSelectAll"></GridCheckboxColumn>
        <GridColumn Field="@(nameof(Order.Id))" Title="@(nameof(Order.Id))" />
        @if (!_Splited)
        {
            <GridColumn Field="@(nameof(Order.Name))" Title="@(nameof(Order.Name))" />
            <GridColumn Field="CreatedAt">
                <Template>
                    @((context as Order).CreatedAt.ToString("dd.MM.yyyy - HH:mm"))
                </Template>
            </GridColumn>
            <GridColumn Field="@(nameof(Order.State))" Title="@(nameof(Order.State))" />
        }
        else
        {
            <GridColumn Field="@(nameof(Order.Name))" Title="@(nameof(Order.Name))" />
            <GridColumn Field="@(nameof(Order.State))" Title="@(nameof(Order.State))" />
        }

    </GridColumns>
</TelerikGrid>

@code {

    bool ShowSelectAll;
    bool _Splited = false;
    public int TotalOrders { get; set; } = 1000;

    public IEnumerable<Order> GridData { get; set; }

    protected override async Task OnInitializedAsync()
    {
    }

    protected async Task OnSelect(IEnumerable<Order> objectList)
    {
        if (objectList.Count() == 1) // considered as single select, so it goes to SplitView and the list needs to shrink
        {
            _Splited = true;
        }
        else // it's in the multi-select mode, so it stays or gets back to the list
        {
            _Splited = false;
        }
    }

    private async Task<IEnumerable<Order>> LoadData()
    {
        var OrderData = new List<Order>();
        for (int i = 1; i < 1001; i++)
        {
            OrderData.Add(new Order()
            {
                Id = Guid.NewGuid(),
                Name = $"Order {i}",
                CreatedAt = DateTime.Now.AddDays((Convert.ToInt32(new Random().Next(10)))),
                State = (OrderState)new Random().Next(0, 2),
            });
        }

        return OrderData.AsEnumerable();
    }

    protected async Task ReadOrders(GridReadEventArgs args)
    {
        int pageNo = args.Request.Page;
        int pageSize = 100;
        var totalData = await LoadData();
        GridData = totalData.Skip(pageSize * (pageNo - 1)).Take(pageSize);
    }


    public class Order
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public DateTime CreatedAt { get; set; }
        public OrderState State { get; set; }

    }

    public enum OrderState
    {
        Open,
        Canceled,
        Closed,
    }
}
0 comments