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

Offline storage and date parsing

1 Answer 67 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 02 Jun 2015, 02:13 PM

So, I have a data source set up like this:

    var bdModel = kendo.observable({

        bdSource: new kendo.data.DataSource({
            offlineStorage: {
                getItem: function () {
                    return dtbd
                },
                setItem: function () {

                }
            },
...//transport, etc.
            schema: {
                data: "Main",
                model: {
                    id: "GUID",
                    fields: {
                        GUID: { editable: false, type: "string" },
                        CompanyName: { validation: { required: true }, type: "string" },
                        CompanyGUID: { validation: { required: true }, type: "string" },
                        Description: { validation: { required: true }, type: "string" },
                        LocationGUID: { type: "string" },
                        StartDate: { type: "date" },
                        EndDate: { type: "date" },
                        UserGUID: { type: "string" },
                        WorkgroupGUID: { type: "string" },
                        BusDevStatusGUID: { type: "string" },
                        EstEndDate: { type: "date" },
                        EstCloseProbability: { type: "string" },
                        EstTotalValue: { type: "string" },
                        BusDevFeeStructureGUID: { type: "string" },
                        SearchGUID: { type: "string" },
                        BDCode: { type: "string" },
                        Login: { type: "string" },
                        Search: { type: "string" },
                        LocationName: { type: "string" },
                        CurrencyGUID: { type: "string" },
                    }
                }
            }
        }),
    });

 

where dtbd is a local variable retrieved from local storage after being set by a function like so:

  var bdview = bdModel.bdSource.view()[0]

        var myObj = {};
        myObj["GUID"] = bdview.GUID;
        myObj["BD"] = bdModel.bdSource.data();

       systemvariable.push(myObj);
       localStorage.setItem("dtBD", JSON.stringify(systemvariable))

 It works great for any string fields, but the dates i'm using for kendo datepicker controls don't load properly. Is there an additional step I need to take somewhere to handle the field types properly?

 

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 04 Jun 2015, 11:19 AM
Hello Bryan,

Does it work if you use the built-in offlineStorage implementation? I mean just to set the offlineStorage key as a string:

offlineStorage: "dtbd"

The DataSource would do date parsing in this case out of the box. Otherwise you have to manually parse JavaScript dates because JSON.parse doesn't do this automatically.

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Bryan
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or