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

Problem with date parsing

5 Answers 758 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 22 Apr 2013, 03:48 PM
Hi,
I'm trying to load a dataSource date field with a Javascript date value like 1366408800000. The grid will not display the value - do I need to strip off the time aspect?
If i change the field to dateTime type it simply displays the full number + when editing it treats it like a number - with no date picker - I'd like it to treat it like a date, with correct formating.
Regards,
Jack

5 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 22 Apr 2013, 04:24 PM
Hi Jack,

I assume that the problem is connected with the field type - dateTime type does not exists. The correct syntax is type: "date", which transforms the timestamp into valid JavaScript date object.

In case the syntax that you use is correct, please provide the configuration of the DataSource as well as sample of the data/Json response. In this way I would be able to examine your case in details and assist you further. Thank you in advance for the cooperation.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Tom
Top achievements
Rank 1
answered on 22 Apr 2013, 04:40 PM
Hi Alexander,

Here is the Json data from the server:
{"employeeCommissionPmntsId":"8045cd00-9275-4e94-847b-f9db35ad425a","date":"1366408800000","employee":"Ran Vermeulen","employee_id":"GUID_eb63c54c-4d25-4348-89ea-c275e572386d","branch":"Amsterdam","branch_id":"VATitNethBVAmsterdam","currency":"EUR","amount":13.11,"exchangeRateDate":"-2208996000000"}

and here is the JS datasource def:

this.dataSource = new kendo.data.DataSource({
  transport: {
    read: {
      type: "GET",
      url: Dragon.apiUrl('commission/payments'),
      dataType: "json"
    },
    parameterMap: function() {
      return $.param({
        branches: _this.$el.find("#branches").val(),
        employees: _this.$el.find("#employees").val(),
        status: _this.$el.find("#status").val(),
        contentType: "application/json"
      });
    },
    update: {
      type: "POST",
      url: Dragon.apiUrl('commission/payment/update'),
      contentType: "application/json"
    }
  },
  schema: {
    model: {
      fields: {
        employeeCommissionPmntsId: {
          type: "string"
        },
        date: {
          type: "date"
        },
        employee: {
          type: "string",
          editable: false
        },
        employee_id: {
          type: "string",
          editable: false
        },
        branch: {
          type: "string",
          editable: false
        },
        branch_id: {
          type: "string",
          editable: false
        },
        currency: {
          type: "string",
          editable: false
        },
        amount: {
          type: "number",
          editable: false
        },
        exchangeRateDate: {
          type: "date",
          editable: false
        }
      }
    }
  }
});

With this config, the dates are nulled when they hit the server
0
Brian
Top achievements
Rank 1
answered on 22 Apr 2013, 06:32 PM
On your date column definition try passing in a display template similar to this: "#= new Date(parseInt(date) #"
0
Tom
Top achievements
Rank 1
answered on 22 Apr 2013, 07:52 PM
template doesn't help, because the date is nulled (must be by Kendo) when it is pulled into the dataSource - seems simply the date format "date":"1366408800000" is not acceptable to Kendo or something. 
0
Alexander Valchev
Telerik team
answered on 24 Apr 2013, 07:55 AM
Hi Jack,

Thank you for providing code snippets.
The problem indeed is that the date format is not recognized from kendo.parseDate method. To fix the issue, you can define a custom parser function. In it you should transform the "data" value info valid JavaScript Date.
One possible approach is to use Brian's technique (but in the parser function) or to use kendo.parseDate and to specify the exact format.

date: {
    type: "date",
    parse: function (data) {
        return new Date(parseInt(data));
    }
},

In this way, the Grid will store and submit the field as date. If you want to customize the way this date is displayed in the grid, please use format or template.

For your convenience I prepared a small sample: http://jsbin.com/adasum/2/edit

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Tom
Top achievements
Rank 1
Brian
Top achievements
Rank 1
Share this question
or