I am having trouble with dates in my grid. Please have a look at the result below.
For testing purposes I set up the most basic implementation of your grid (without any locales) and retrieve the dates in ISO8601format. When just setting the column type to "date" the displayed dates do not make sense any more. To my surprise using a certain "format" only works in some cases.
Any idea what is causing this display (/parsing?) issue?
Many thanks in advance for your help.
They are strings. The store uses a default model which doesn't know that your data field called "date" holds the dates. You need to define store fields, or define a new Model and set to the Store as modelClass.
store : {
fields : [
{ name : 'date', type : 'date' }
],
data : [
{
date : '2021-06-09T06:37:22.617'
},
{
date : '2019-12-31T00:00:00'
},
{
date : '2020-01-02T13:37:59'
}
]
}
Try now:
grid.store.map(r => r.date)
// (3) [Wed Jun 09 2021 06:37:22 GMT+0300 (GMT+03:00), Tue Dec 31 2019 00:00:00 GMT+0300 (GMT+03:00), Thu Jan 02 2020 13:37:59 GMT+0300 (GMT+03:00)]
Or alternative solution:
import Model from '../../lib/Core/data/Model.js';
import '../../lib/Grid/column/DateColumn.js';
class MyModel extends Model {
static get $name() {
return 'MyModel';
}
static get fields() {
return [
{ name : 'date', type : 'date' }
];
}
}
.....
store : {
modelClass : MyModel,
data : [
{
date : '2021-06-09T06:37:22.617'
},
{
date : '2019-12-31T00:00:00'
},
{
date : '2020-01-02T13:37:59'
}
]
}
Hi Pavel,
thanks for clearing this up. Makes sense for me now. I expected the "type: 'date'" attribute in the column definition to do more than just allow for formatting (e.g. parsing the date-string). But your approach with field definitions in the store works for me.
Cheers!