Unplanned
Last Updated: 01 Feb 2023 15:59 by Oleg
Oleg
Created on: 01 Feb 2023 15:59
Category: TreeList
Type: Bug Report
2
Problem with ToTreeDataSourceResult method when filtering on root and child level

Bug report

Problem with ToTreeDataSourceResult method when filtering on root and child level.

Also applying filtering causes a significant slowdown in the query created by the ToTreeDataSourceResult method even when applied to small datasets.

Reproduction of the problem

Please refer to the code below and simply filter the first column with the value of 5.

//View
@(Html.Kendo().TreeList<WebApplication1.Models.SerialModel>()
        .Name("treelist")
         .Toolbar(toolbar => toolbar.Create().Text("New Level"))
        .Columns(columns =>
        {
            columns.Add().Field(e => e.RecordID).Width(280);
            columns.Add().Field(e => e.SerialNumber).Width(160);
            columns.Add().Field(e => e.Name);
            columns.Add().Field(e => e.Location).Width(200);
            columns.Add().Field(e => e.ParentID).Width(140);
            columns.Add().Command(c =>
            {
                c.CreateChild().Text("New Child");
                c.Edit();
                c.Destroy();
               
            }).Width(250);
        })
        .Editable(editable => editable.Mode("inline")).Filterable(true).Filterable(f => f.Extra(false))
        .DataSource(dataSource => dataSource
            .Read(read => read.Action("TreeListData", "Home"))
            //.ServerOperation(false)
            .Model(m =>
            {
                m.Id(f => f.RecordID);
                m.ParentId(f => f.ParentID).DefaultValue("0");
                
            })
        )
        .Height(540)
)

//Controller code: 
public ActionResult TreeListData([DataSourceRequest]DataSourceRequest request, int? id)
        {
            var source = Enumerable.Range(1, 5).Select(x => new SerialModel()
            {
                RecordID = x,
                SerialNumber = x,
                Name = "Name " + x,
                Location = "Location " + x,
                hasChildren =  true,
                ParentID = x < 5 ? 0 : (x / 5)
            });
            return Json(source.ToTreeDataSourceResult(request, e => e.RecordID,
                e => e.ParentID, e => id.HasValue ? e.ParentID == id : e.ParentID == 0, m => m));
        }

Expected/desired behavior

Instead of 1 record it returns 2 same items.

Filtering of the TreeList should be as fast as sorting.

Environment

  • Kendo UI version: 2023.1.117
0 comments