Fuczak
Fuczak

Reputation: 350

Telerik Blazor TreeList SelectedItemsChanged async

I have this example code: https://blazorrepl.telerik.com/Qwumvklf39dvgfer21

In the TreeList:

<TelerikTreeList Data="@Data"
                 IdField="EmployeeId"
                 ParentIdField="ReportsTo"
                 Pageable="false"
                 SelectionMode="@SelectionMode"
                 SelectedItems="@SelectedItems"
                 SelectedItemsChanged="@(async (IEnumerable<EmployeeDirectoryDto> itemsList) => await HandleSelectionChange(itemsList))"
                 Height="300px">
    <TreeListColumns>
        <TreeListCheckboxColumn SelectAll="@ShowSelectAll" SelectChildren="true"></TreeListCheckboxColumn>
        <TreeListColumn Field="FirstName" Title="First Name" Width="350px" Expandable="true"></TreeListColumn>
        <TreeListColumn Field="LastName" Title="Last Name"></TreeListColumn>
        <TreeListColumn Field="HireDate" Title="Hire Date" Width="200px"></TreeListColumn>
    </TreeListColumns>
</TelerikTreeList>

And handler:

    private async Task HandleSelectionChange(IEnumerable<EmployeeDirectoryDto> selectedFilters)
    {
        await Task.Delay(2000);//Simulate http call
        SelectedItems = selectedFilters.AsEnumerable<EmployeeDirectoryDto>();
    }

Scenario: Select checkbox to select all items. Result: Items get selected internally, but UI is still showing no items selected.

If async/await is removed then it works as expected and all items get selected. I added a Task.Delay just to simulate some long running http call happening on every selection change.

What am I missing here?

Upvotes: 0

Views: 361

Answers (1)

Dan Benson
Dan Benson

Reputation: 26

It doesn't work asynchronously, though I think they are adding an OnRowClick event that will work aysnc in 3.1.

In the meantime, you need to do this:

private void HandleSelectionChange(IEnumerable<EmployeeDirectoryDto> selectedFilters)
{
    InvokeAsync(() => Task.Delay(2000));//Simulate http call
    SelectedItems = selectedFilters.AsEnumerable<EmployeeDirectoryDto>();
} 

Upvotes: 1

Related Questions