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

Store the state in any way (cookies etc.) to restore it on a page load?

5 Answers 171 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Stephan
Top achievements
Rank 1
Stephan asked on 26 Feb 2013, 12:55 PM

Hello,

after the page containing the tree view is refreshed, the state isn’t remembered so the tree view is collapsed totally. We have the requirement that the state is unchanged on a refresh or navigation operation on the browser.

So our question: Is it possible to store the state in any way (cookies etc.) to restore it on a page load?

Thanks in advance.

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 28 Feb 2013, 08:48 AM
Hello Stephan,

I attached a sample project which shows one possible implementation to preserve the state. Check it and let me know if you have any questions.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Stephan
Top achievements
Rank 1
answered on 04 Mar 2013, 09:46 AM
Hello,

your example is not fully working yet. The treeview is displayed correctly and all expanded and collapsed states are handled the right way.
But if we attach the collapsed and expand event we get an unexpected behavior:

Example
+ Root
+ Foo
 - Foo 1
 - Foo 2
- bar
- blubb

After the page reload we get the correct treeview, but if the users click on the node Foo (which is already expanded), the expanded-event is raised, instead of the collapsed-event. If the users click again the collapsed-event is raised like expected.

The error appears in our projekt as well as in your sample project.

Thanks in advance.
0
Daniel
Telerik team
answered on 06 Mar 2013, 08:51 AM
Hello again Stephan,

This is a known issue that has already been fixed in the latest internal builds and in the beta release, and the changes will be available in the next official release. The problem can be workaround with the current version by setting the "data-expanded" attribute on the nodes e.g.

.ItemDataBound((item, customer) =>
    {
        item.Text = customer.ContactName;
        item.Id = customer.CustomerID;                         
        item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(customer.CustomerID);
        if (item.Expanded)
        {
            item.HtmlAttributes["data-expanded"] = "true";
        }               
    })
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Natraj
Top achievements
Rank 1
answered on 08 Apr 2014, 02:18 PM
Hey Daniel,
When I tried to execute this sample project (from PersistStateKendoTreeView.zip). I got following error. would you able to assists me on this?

Compiler Error Message: CS1061: 'PersistStateKendoTreeView.Models.Customers' does not contain a definition for 'Orders' and no extension method 'Orders' accepting a first argument of type 'PersistStateKendoTreeView.Models.Customers' could be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 21: }
Line 22: })
Line 23: .Children(customers => customers.Orders)
Line 24: );
Line 25:
0
Daniel
Telerik team
answered on 10 Apr 2014, 09:36 AM
Hello,

Have you made any modifications to the project. It is running as expected on my side. The exception messages suggests that the "Orders" navigational property is removed from the Customer class.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
TreeView
Asked by
Stephan
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Stephan
Top achievements
Rank 1
Natraj
Top achievements
Rank 1
Share this question
or