Unplanned
Last Updated: 12 Oct 2020 07:35 by ADMIN
inno
Created on: 12 Oct 2020 07:23
Category: TreeList
Type: Bug Report
1
Rendering does not update when adding a new item until you collapse and expand the node whose children were modified
When I add a child to a node in the TreeList it would not render until I expand or collapse that node.
1 comment
ADMIN
Svetoslav Dimitrov
Posted on: 12 Oct 2020 07:35

Hello,

For the time being a manual refresh of the TreeList would solve the issue.

@using System.Collections.ObjectModel


@if (TreeListVisible)
{
    <TelerikTreeList Data="@Data"
                     ItemsField="DirectReports"
                     HasChildrenField="HasReports"
                     Pageable="true"
                     Sortable="true"
                     FilterMode="@TreeListFilterMode.FilterMenu"
                     Width="100%" Height="600px"
                     Resizable="true" Reorderable="true">
        <TreeListToolBar>
            <TelerikButton OnClick="@AddItem" Icon="@IconName.Plus" Class="mr-sm">Add item</TelerikButton>
        </TreeListToolBar>
        <TreeListColumns>
            <TreeListColumn Expandable="true" Field="Position" Width="400px"></TreeListColumn>
            <TreeListColumn Field="FirstName" Width="200px"></TreeListColumn>
            <TreeListColumn Field="LastName" Width="200px"></TreeListColumn>
            <TreeListColumn Field="EmployeeId" Width="100px"></TreeListColumn>
        </TreeListColumns>
    </TelerikTreeList>
}

@code {
    bool TreeListVisible { get; set; } = true;
    async Task RenderTreelist()
    {
        TreeListVisible = false;
        await Task.Delay(30);
        TreeListVisible = true;
        StateHasChanged();
    }

    // a model to bind the treelist. Should usually be in its own separate location
    public class EmployeeHierarchical
    {
        public int EmployeeId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Position { get; set; }
        public ObservableCollection<EmployeeHierarchical> DirectReports { get; set; }
        public bool HasReports { get; set; }
    }

    // treelist data
    public System.Collections.ObjectModel.ObservableCollection<EmployeeHierarchical> Data { get; set; }

    // fetch the treelist data
    protected override async Task OnInitializedAsync()
    {
        Data = await GetEmployees();
    }

    async Task AddItem()
    {
        Data[0].DirectReports.Insert(0, new EmployeeHierarchical()
        {
            EmployeeId = 1156464,
            FirstName = "FirstName",
            LastName = "LastName",
            Position = "Manager",
            HasReports = false
        });

        Data = new ObservableCollection<EmployeeHierarchical>(Data);
    }

    // The next 200 lines are hardcoded data so you can explore the TreeObservableCollection freely

    async Task<ObservableCollection<EmployeeHierarchical>> GetEmployees()
    {
        ObservableCollection<EmployeeHierarchical> sampleData = new ObservableCollection<EmployeeHierarchical>();

        EmployeeHierarchical theCEO = new EmployeeHierarchical
        {
            EmployeeId = 1,
            FirstName = "Daryl",
            LastName = "Sweeney",
            Position = "CEO",
            HasReports = true
        };

        theCEO.DirectReports = new ObservableCollection<EmployeeHierarchical>
{
            new EmployeeHierarchical
            {
                EmployeeId = 2,
                FirstName = "Guy",
                LastName = "Wooten",
                Position = "Chief Technical Officer",
                HasReports = true
            },
            new EmployeeHierarchical
            {
                EmployeeId = 3,
                FirstName = "Nevada",
                LastName = "Hart",
                Position = "Chief Financial Officer",
                HasReports = true,
                DirectReports = new ObservableCollection<EmployeeHierarchical>
{
                    new EmployeeHierarchical
                    {
                        EmployeeId = 24,
                        FirstName = "Zena",
                        LastName = "Stanford",
                        Position = "VP, Finance"
                    }
                }
            }
        };

        theCEO.DirectReports[0].DirectReports = new ObservableCollection<EmployeeHierarchical>
{
            new EmployeeHierarchical
            {
                EmployeeId = 4,
                FirstName = "Buffy",
                LastName = "Weber",
                Position = "VP, Engineering",
                HasReports = true,
                DirectReports = new ObservableCollection<EmployeeHierarchical>
{
                    new EmployeeHierarchical
                    {
                        EmployeeId = 6,
                        FirstName = "Hyacinth",
                        LastName = "Hood",
                        Position = "Team Lead",
                        HasReports = true,
                        DirectReports = new ObservableCollection<EmployeeHierarchical>
        {
                            new EmployeeHierarchical
                            {
                                EmployeeId = 7,
                                FirstName = "Akeem",
                                LastName = "Carr",
                                Position = "Software Developer, Junior"
                            },
                            new EmployeeHierarchical
                            {
                                EmployeeId = 8,
                                FirstName = "Rinah",
                                LastName = "Simon",
                                Position = "Software Developer"
                            }
                        }
                    },
                    new EmployeeHierarchical
                    {
                        EmployeeId = 9,
                        FirstName = "Gage",
                        LastName = "Daniels",
                        Position = "Software Architect"
                    },
                    new EmployeeHierarchical
                    {
                        EmployeeId = 10,
                        FirstName = "Constance",
                        LastName = "Vazquez",
                        Position = "Director, Engineering",
                        HasReports = true,
                        DirectReports = new ObservableCollection<EmployeeHierarchical>
        {
                            new EmployeeHierarchical
                            {
                                EmployeeId = 11,
                                FirstName = "Darrel",
                                LastName = "Solis",
                                Position = "Team Lead",
                                HasReports = true,
                                DirectReports = new ObservableCollection<EmployeeHierarchical>
                {
                                    new EmployeeHierarchical
                                    {
                                        EmployeeId = 12,
                                        FirstName = "Brian",
                                        LastName = "Yang",
                                        Position = "Software Developer, Senior"
                                    },
                                    new EmployeeHierarchical
                                    {
                                        EmployeeId = 13,
                                        FirstName = "Lillian",
                                        LastName = "Bradshaw",
                                        Position = "Software Developer"
                                    },
                                    new EmployeeHierarchical
                                    {
                                        EmployeeId = 14,
                                        FirstName = "Keiko",
                                        LastName = "Espinoza",
                                        Position = "QA Engineer, Junior"
                                    }
                                }
                            }
                        }
                    }
                }
            },
            new EmployeeHierarchical
            {
                EmployeeId = 5,
                FirstName = "Skyler",
                LastName = "Cleveland",
                Position = "VP, Engineering",
                HasReports = true,
                DirectReports = new ObservableCollection<EmployeeHierarchical>
{
                    new EmployeeHierarchical
                    {
                        EmployeeId = 16,
                        FirstName = "Karleigh",
                        LastName = "Garza",
                        Position = "Team Lead",
                        HasReports = true,
                        DirectReports = new ObservableCollection<EmployeeHierarchical>
        {
                            new EmployeeHierarchical
                            {
                                EmployeeId = 17,
                                FirstName = "Elmo",
                                LastName = "Tyson",
                                Position = "Software Developer"
                            },
                            new EmployeeHierarchical
                            {
                                EmployeeId = 18,
                                FirstName = "Stacey",
                                LastName = "Lynn",
                                Position = "QA Engineer",
                                HasReports = true,
                                DirectReports = new ObservableCollection<EmployeeHierarchical>
                {
                                    new EmployeeHierarchical
                                    {
                                        EmployeeId = 19,
                                        FirstName = "Meredith",
                                        LastName = "Parish",
                                        Position = "QA Engineer, Junior"
                                    }
                                }
                            },
                            new EmployeeHierarchical
                            {
                                EmployeeId = 20,
                                FirstName = "Martha",
                                LastName = "Sargent",
                                Position = "Software Developer, Senior"
                            },
                            new EmployeeHierarchical
                            {
                                EmployeeId = 21,
                                FirstName = "Cassady",
                                LastName = "Whitley",
                                Position = "Software Developer"
                            },
                            new EmployeeHierarchical
                            {
                                EmployeeId = 22,
                                FirstName = "Haviva",
                                LastName = "Campbell",
                                Position = "Support Officer"
                            },
                            new EmployeeHierarchical
                            {
                                EmployeeId = 23,
                                FirstName = "Cameron",
                                LastName = "Ayers",
                                Position = "Support Officer"
                            }
                        }
                    }
                }
            }
        };

        sampleData.Add(theCEO);

        return await Task.FromResult(sampleData);
    }
}

Regards,
Svetoslav Dimitrov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.