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

Restoring treelist expanded state after refresh

2 Answers 865 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Keijo
Top achievements
Rank 1
Keijo asked on 05 Jun 2017, 09:35 AM
Is it possible to restore tree to the same opened state after page update with remote binding.

2 Answers, 1 is accepted

Sort by
0
Keijo
Top achievements
Rank 1
answered on 05 Jun 2017, 09:49 AM
This question was ment to be posted on: http://www.telerik.com/forums/aspnet-mvc/treelist forums. 
0
Viktor Tachev
Telerik team
answered on 07 Jun 2017, 08:28 AM
Hello Keijo,

In order to implement the behavior you can use an approach similar to the one described in the thread below. 


The difference in your case would be that you should expand the items and not collapse them. The modified code for persisting the expanded items would look like below:


$("#save").click(function () {
    localStorage["toExpand"] = JSON.stringify($.map($("#treelist .k-i-collapse").closest("tr"), function (val, idx) { return $(val).index() }));
});
 
$("#load").click(function () {
    var items = localStorage["toExpand"];
    if (items) {
        items = JSON.parse(items);
        var tl = $("#treelist").data("kendoTreeList");
        $.each(items, function (idx, val) {
            var tr = tl.content.find("tr").eq(val);
            tl.expand(tr);
        })
    }
});


Regards,
Viktor Tachev
Progress Telerik
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
TreeList
Asked by
Keijo
Top achievements
Rank 1
Answers by
Keijo
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or