Saving a Kendo datasource using jStorage -


i'm adding , removing data kendo datasource. wish save localstorage, , able read again localstorage.

here i've attempted use jstorage saving , loading of data.

how it's loaded:

if ($.jstorage.get('favoritter') != null) {     var datakilde_favoritter = $.jstorage.get('favoritter'); } else {     var data = [         {id: 5, name: "link one", url: "http://www.linkone.com" }     ];     var datakilde_favoritter = new kendo.data.datasource({         data: data,         sort: { field: "name", dir: "asc" }     }); } 

how it's saved:

$.jstorage.set('favoritter', datakilde_favoritter); 

define datasource as:

var ds = new kendo.data.datasource({     transport: {         read   : function (op) {             var data = $.jstorage.get('favoritter');             if (!data) {                 data = [                     {id: 5, name: "link one", url: "http://www.linkone.com" }                 ];             }             op.success(data);         },         update : function (op) {             $.jstorage.set("favoritter", ds.data());             op.success(op.data);         },         destroy: function (op) {             console.log("destroy", ds.data());             $.jstorage.set("favoritter", ds.data());             op.success(op.data);         },         create : function (op) {             $.jstorage.set("favoritter", ds.data());             op.success(op.data);         }     },     sort     : { field: "name", dir: "asc" },     pagesize : 10,     schema   : {         model: {             id    : "id",             fields: {                 id  : { type: 'number' },                 name: { type: 'string' }             }         }     } }); 

you might consider removing create , destroy if not needed.

and grid like:

var grid = $("#grid").kendogrid({     datasource: ds,     editable  : "popup",     pageable  : true,     toolbar   : ["create"],     columns   : [         { command: ["edit", "destroy"], width: 100 },         { field: "id", width: 90, title: "#" },         { field: "name", width: 90, title: "url name" }     ] }).data("kendogrid"); 

basically when updating need invoke op.success data returned server. in case since browser itself, don't need return original data.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -