This is a migrated thread and some comments may be shown as answers.

Treeview onSelect event and Grid

1 Answer 358 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Robert Madrian asked on 06 Jan 2017, 10:41 AM

Hi,

I have a treeview and a grid where the select node id is used in the Data Event from the grid to filter the data based on the treeview selection.

function onMitglieddokumente_DataFilter() {
    var treeView = $("#tvwDokumentenablagestruktur").data("kendoTreeView");
    var selectedNode = treeView.select();
    var id = 1;       
    if (selectedNode.length != 0) {
        var item = treeView.dataItem(selectedNode);
        id = item.id;                  
    }
    return {
        mitgliedid: @ViewContext.RouteData.Values["mitgliedid"],
        ordnerid: id
    };
}

 

in the Treeview onSelect Event I refresh the grid datasource:

function onTreeviewChange(e) {
        $("#gridMitglieddokumente").data("kendoListView").dataSource.read();
    };

 

the Problem with that solution is, that I always get the latest selection of the Treeview not the current one!

if I use the onChange Event the refresh is fired more than ones because it fires on selection and on expand...

robert

 

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 09 Jan 2017, 11:19 AM

Hello Robert,

The TreeView select event is triggered before the selection is updated, to allow the event to be prevented. To resolve the problem, you can use one of these approaches:

  • use a setTimeout in the select event handler

    function onTreeviewChange(e) {
        setTimeout(function() {
            $("#gridMitglieddokumente").data("kendoListView").dataSource.read();
        });
    };
  • pass the selected item id to the datasource fetch method.

    $("#gridMitglieddokumente").data("kendoListView").dataSource.fetch({
        id: this.dataItem(e.node),
        mitgliedid: @ViewContext.RouteData.Values["mitgliedid"]
    });
Regards,
Alex Gyoshev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TreeView
Asked by
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Answers by
Alex Gyoshev
Telerik team
Share this question
or