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

Need help with date-format and filtering

3 Answers 212 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tonny
Top achievements
Rank 1
Tonny asked on 22 Oct 2015, 02:09 PM

Hi!

 

I have a simple grid set up, like this:

 

$('#assessment-list').kendoGrid({
    columns: [
        { field: 'CreatedDate', title: 'Dato for henvendelse', template: '#= kendo.parseDate(CreatedDate, "yyyy-MM-ddTHH:mm:ss.ff") #', format: "{0: dd-MM-yyyy}" },

<<more cols>>

    ],
    dataSource: {
        transport: {
            read: {
                url: ​<<api endpoint>>,
                dataType: 'json'
            }
        }
    },
    sortable: true,
    pageable: {
        info: false
    },
    filterable: true
});

...and that date field refuses to do what I want.

The date comes from an api as json, so the grid datasource gets it as a string. I thought using a template was the way to "pre-process" it into a date to let the grid work right, but no luck. Problems:​

1) The date is parsed fine, but the output is, eg., Wed Oct 21 2015 14:12:00 GMT+0200 (Romance Standard Time), which is less than useful as this ignores both the format of the field and the current kendo.culture: "da-DK".

2) The filter menu (which does obey the culture setting and is nicely translated) treats the column data as string, having starts-with and ends-with options but no less-than / greater-than as you'd expect when working with dates.

 

I can call kendo.toString() in the template to fix the display issue, but this leaves the filter treating the column values as string. Can anyone explain how to configure this to fix both problems, or show me some other way to process the data from the datasource, please?

 

TIA

3 Answers, 1 is accepted

Sort by
0
Tonny
Top achievements
Rank 1
answered on 23 Oct 2015, 11:28 AM

I found an SO post with the solution: columns.type: 'date' sets the column data type and fixes the filter menu even with a .toString() in the template.Very useful.

Why is the columns.type configuration option not included in the API docs?

0
Accepted
Boyan Dimitrov
Telerik team
answered on 26 Oct 2015, 09:27 AM
Hello,

The reason why there is no columns.type configuration option in the Kendo UI Grid API is because the data type option should be defined in the model configuration section of the Kendo UI DataSource. 

Please refer to the Model.define method and specifically to the example, that shows how to define the data type for the model field. 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Tonny
Top achievements
Rank 1
answered on 26 Oct 2015, 09:56 AM

Hi,

[quote]
The reason why there is no columns.type configuration option in the Kendo UI Grid API is because the data type option should be defined in the model configuration section of the Kendo UI DataSource.

[/quote]

Ok. A note to that effect in the docs would still have been very helpful.

I'll take a look at the examples and the Model docs.

Thanks

Tags
Grid
Asked by
Tonny
Top achievements
Rank 1
Answers by
Tonny
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or