I am building tree component and I want to save it's state (expanded nodes etc) so I can recreate that tree state when component is loaded again. What are available mechanisms in Lightning for this?

  • Do you want to store the state just for the current session of the user or permanently? – RedDevil Jul 18 '17 at 12:40
  • @RedDevil For each user, but I don't want to use database for this – Vladyslav K Jul 18 '17 at 12:41

You can use Platform Cache for this purpose. In combination with server-side controller it will fit your desire.

Use Session cache to store data related to each user

  • Would you mind adding a few references or code examples. Google didn't find a single result showing how to use a custom Sesson cache to speed up Lightning components. – Robert Sösemann Dec 7 '17 at 12:47

You can use localStorage in Summer'17

window.localStorage.setItem('name', value);
var v = window.localStorage.getItem('name');
  • can you share a link where it says so? as there is bug related to Summer '16, that it is not fixed success.salesforce.com/issues_view?id=a1p3A000000IYE6QAO – Oleksandr Berehovskyi Jul 18 '17 at 12:53
  • 1
    In my org ( summer'17) i'm using this approach, and it is working. "In Summer '17, LockerService is auto-activated for all orgs with no option to disable." – Roman Jul 18 '17 at 12:58
  • 3
    @AlexanderBerehovskiy localStorage is working fine for me too (Summer '17 org). But what you suggested is better for this(question's) purpose. – SE_User Jul 18 '17 at 13:01
  • window.sessionStorage.getItem ... doesn't work with data not created by Salesforce sessionStorage – kabrice Jun 14 '20 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.