Offline storage and date parsing

2 posts, 0 answers
  1. Bryan
    Bryan avatar
    28 posts
    Member since:
    Oct 2014

    Posted 02 Jun 2015 Link to this post

    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?

     

  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 04 Jun 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
Back to Top