Restoring treelist expanded state after refresh

3 posts, 0 answers
  1. Keijo
    Keijo avatar
    4 posts
    Member since:
    Nov 2016

    Posted 05 Jun Link to this post

    Is it possible to restore tree to the same opened state after page update with remote binding.
  2. Keijo
    Keijo avatar
    4 posts
    Member since:
    Nov 2016

    Posted 05 Jun in reply to Keijo Link to this post

    This question was ment to be posted on: http://www.telerik.com/forums/aspnet-mvc/treelist forums. 
  3. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1768 posts

    Posted 07 Jun Link to this post

    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.
Back to Top