expandPath triggers Expand event of TreeView after Read

4 posts, 1 answers
  1. CONTENTShare
    CONTENTShare avatar
    4 posts
    Member since:
    Jun 2013

    Posted 21 Feb Link to this post

    Hi,

    we are using TreeView with on demand loading of nodes. There is case when we need to select specific node that possibly wasn't loaded yet. So we get all needed IDs and use .expandPath expand one by one parent node of the target node. This was working fine with old 2014 kendo for mvc version. However, after switching to newest 2017.1 we are having a problem.

    When .expandPath is called, we expect Expand event is called first - where we set up some values that will be used in reading of data. Then, expand would call reading of data where this prepared values are used. However, with new 2017.1 it always happens that .Data function of Read is called before Expand, which doesn't make sense for me, but could be I'm not understanding how it works.

    Here are the code samples.

    @(Html.Kendo().TreeView()
        .Name("treeview")
        .DataTextField("Name")
        .DataImageUrlField("image")
        .DataSource(dataSource => dataSource
            .Read(read => read
                .Action("GetFolderDefinitionsProjectsAndActs", "ProjectsCrud").Data("additionalData")
            )
        ).Events(events => events
        .Expand("onExpand").Select("onNodeSelected").DataBound("onTreeViewDataBound")
        )
    )

     

    function additionalData(e) {
        return {
            id: startFolderID,
            nodeType: expandLevel,
            folderDefinitionID: folderDefinitionID
        };
    }

       

    function onExpand(ex) {
            var tree = $('#treeview').data('kendoTreeView');
            var dataItem = tree.dataItem(ex.node);
            expandLevel = dataItem.levelName;
            folderDefinitionID = dataItem.FolderDefinitionID;
            return true;
        }

     

    So, at some point we call

    var treeview = $("#treeview").data("kendoTreeView");
    treeview.expandPath(returnData);

    and we would expect function onExpand to be called before additionalData, but instead additionalData is called before onExpand.

    Is this expected behavior?

  2. Answer
    Ivan Danchev
    Admin
    Ivan Danchev avatar
    1332 posts

    Posted 22 Feb Link to this post

    Hello Nikola,

    Indeed there has been a change in the order of calling the data source's read data function and the expand event and it happened in Q1 2016 SP2 (version 2016.1.406). Since this Kendo UI version the data function is called first and then the expand event fires. This change is related to several bug fixes with regard to the expandPath method, described in the release notes for this particular release.

    Regards,
    Ivan Danchev
    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.
  3. CONTENTShare
    CONTENTShare avatar
    4 posts
    Member since:
    Jun 2013

    Posted 22 Feb Link to this post

    Hello Ivan,

    thank you for clarifying this. So we now do everything in .Data function instead in .Expand and it is OK, we just didn't expected this new order of things.

    Best Regards

  4. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1332 posts

    Posted 24 Feb Link to this post

    Hello Nikola,

    I am glad you made it work in the data function. Indeed this change in the order of event firing/function calling has not been documented, which can cause confusion with regard to what the actual expected behavior is. We are doing our best to avoid such cases and document all changes (breaking or not).

    Regards,
    Ivan Danchev
    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.
Back to Top