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

Storing App User preferences in LocalStorage

1 Answer 164 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
David
Top achievements
Rank 1
David asked on 08 Dec 2015, 04:06 PM
I am looking to store some user preference settings in LocalStorage.  Is there a good hybrid sample (or full set of example code) out there that shows how to set the datasource to localstorage and use the Kendo UI listview?  Is there a Best Practice for storing user preferences?

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 11 Dec 2015, 12:09 PM
Hi David,

You shouldn't need the DataSource to read and store user preferences. You just need to define methods to read the user preferences on start of the app (deviceready event) from local storage and to store new preferences if the user modifies them.

What do you need to display in the ListView? If it is a list of all preferences, you can just create an object that stores all preferences, e.g. :
app.homeView = kendo.observable({
    preferences: {
        location: "London",
        language: "en-US",
        timeZone: "GMT",
        sendNotifications: false
    }
});

Then, you can define a static ListView bound to these preferences:
<div data-role="view" data-title="Home View" data-layout="main" data-model="app.homeView" >
        <ul data-role="listview">
            <li><label>Location: </label><span data-bind="text: preferences.location"></span></li>
            <li><label>Language: </label><span data-bind="text: preferences.language"></span></li>
            <li><label>Time zone: </label><span data-bind="text: preferences.timeZone"></span></li>
            <li>
                <label>Get notifications:</label>
                <span style="color:green" data-bind="visible:preferences.sendNotifications">Yes</span>
                <span style="color:red" data-bind="invisible:preferences.sendNotifications">No</span>
            </li>
        </ul>
</div>


Regards,
Tsvetina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or