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

datasource grid date formatting

2 Answers 88 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 13 Nov 2020, 06:37 PM

https://dojo.telerik.com/aDalAvav/3

 

Dear sirs, the architecture requires to call "doc.subdoc" field by it's name.

 

So I have troubles formatting the dates to my localdate, as you can see the example.

 

Please, help. 

Thank you.

2 Answers, 1 is accepted

Sort by
0
Accepted
Stoyan
Telerik team
answered on 17 Nov 2020, 12:29 PM

Hello, Max,
thank you for sharing your code.

The second column in the grid is not getting formatted correctly since the "bd" column field is a complex type and should be of type "object":

schema: {
      	model:{
          id:"email",
          fields:{
            dt:{type:"date"},
            bd:{type:"object"}
          }
        }
      }

You can read more about the supported dataSource types in an editable Kendo UI Grid here.

That said, to format the column as a date you can use a Kendo UI Template. This will ensure the required rendering, but as the "bd" field it is of type "object" you will need to specify the editor for the column:

{ field: "bd.dt", template:"#=kendo.toString(kendo.parseDate(bd.dt),'d')#", editor:datePickerEditor}

This way on editing the "bd.dt" field will be parsed as a date correctly. This article goes over the requirements for defining a custom grid editor and you can see a runnable demo here. For your scenario you can define a DatePicker editor via the datePickerEditor function:

function datePickerEditor(container, options) {
            $('<input name="' + options.field + '"/>')
                .appendTo(container)
                .kendoDatePicker();
        }

I applied the above-suggested approach to your example and you can review it here: https://dojo.telerik.com/@Stoyan/IpEJOtoF

Please don't hesitate to reach out if more questions arise.

Regards,
Stoyan
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Max
Top achievements
Rank 1
answered on 18 Nov 2020, 04:52 AM

Sir, thank you for complete and exhaustive answer.

 

Tags
Data Source
Asked by
Max
Top achievements
Rank 1
Answers by
Stoyan
Telerik team
Max
Top achievements
Rank 1
Share this question
or