Hi experts,
I want to us a datepicker within a grid with localized date (german format)
The grid columns are set as
columns: [
{ field: 'coursecalblockid', headerText: 'ID', width: 50, textAlign: 'Right', visible: false, isPrimaryKey: true },
{ field: 'DateFromLocalized', headerText: 'Date from', editType: 'datepickeredit', format: 'dd.MM.yyyy', edit: {params: { format: 'dd.MM.yyyy'}}, width: 120, textAlign: 'Left', allowEditing: true},
{ field: 'DateToLocalized', headerText: 'Date to', editType: 'datepickeredit', format:'dd.MM.yyyy', width: 120, textAlign: 'Left', allowEditing: true},
{ field: 'caption', headerText: 'Bezeichnung', width: 80, textAlign: 'Left', allowEditing: true},
],
The grid is filled with
{
"result": [
{
"coursecalblockid": 1,
"caption": "Grundlehrgang",
"DateFromLocalized": "16.08.2021",
"DateToLocalized": "22.08.2021",
"DateFromJS": "08/16/2021",
"DateToJS": "08/22/2021"
},
{
"coursecalblockid": 2,
"caption": "Lehrgang Praxis",
"DateFromLocalized": "01.10.2021",
"DateToLocalized": "04.10.2021",
"DateFromJS": "10/01/2021",
"DateToJS": "10/04/2021"
}
],
"count": 2
}
The date is displayed within every row, everything seems fine.
But when I enter edit mode the date field is empty and the datepicker is not set to the current value.
What can I do?
Regards,
Stephan
Many thaks for your quick reply.
I have learned, that the JSON is always a string representation of the data.
And for date you should use
2012-04-23T18:25:43.511Z
as described here.
https://stackoverflow.com/questions/10286204/what-is-the-right-json-date-format
So my response from the webserver is:
{
"result": [
{
"coursecalblockid": 1,
"caption": "Grundlehrgang",
"DateFromJSDate": "2021-08-16T00:00:00+02:00",
"DateToJSDate": "2021-08-22T00:00:00+02:00",
"NoOfDays": 7
},
{
"coursecalblockid": 2,
"caption": "Lehrgang Praxis",
"DateFromJSDate": "2021-10-01T00:00:00+02:00",
"DateToJSDate": "2021-10-04T00:00:00+02:00",
"NoOfDays": 4
}
],
"count": 2
}
This works now.
Regards,
Stephan
Hi support,
as I wrote above the edit mode is working.
But changed data of the date is not sent to the server.
This happens either with crudUrl and with updateUrl.
The data sent to the server is:
{"value":{"coursecalblockid":1,"caption":"Grundlehrgang2","DateFromLocalized":"16.08.2021","DateToLocalized":"22.08.2021","DateFromJSDate":"2021-08-15T22:00:00.000Z","DateToJSDate":"2021-08-22T22:00:00.000Z","NoOfDays":7},"action":"update","keyColumn":"coursecalblockid","key":1,"params":{"_csrf":"ZGNUgI6fq6BaH_WaJDRAeIMEmy9eWFTS-m8E66K5Qm5WDCbJ4v3y8WhIpcgRUyQA5XHJFmcZYIG-Ck3d1_IoBw==","courseid":1},"_csrf":"ZGNUgI6fq6BaH_WaJDRAeIMEmy9eWFTS-m8E66K5Qm5WDCbJ4v3y8WhIpcgRUyQA5XHJFmcZYIG-Ck3d1_IoBw==","courseid":1}
The new correct values that should be sent to the server are:
caption: Grundlehrgang2
dateToJSDate: 2021-08-23T....
Regards,
Stephan
<script>
// Grid’s actionBegin event handler
function actionBegin(args) {
if (args.requestType == "save") {
var grid = document.getElementById("Grid").ej2_instances[0];
var cols = grid.columns;
for (var i = 0; i < cols.length; i++) {
if (cols[i].type == "date" || cols[i].type == "datetime") {
var date = args.data[cols[i].field];
args.data[cols[i].field] = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getMilliseconds()));
}
}
}
}
</script> |