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

RadGrid GridDateTimeColumn ignoring DataFormatString?

2 Answers 606 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 18 Oct 2017, 06:42 AM

I have a column defined like :-

<telerik:GridDateTimeColumn DataField="ReceivedDateTime" SortExpression="ReceivedDateTime"  DataType="System.DateTime" DataFormatString="{0:dd/MM/yyyy}" />

 

and the data is passed in a datatable, and defined using :-

row(ReceivedDateTime.FieldIndex) = ReceivedDateTime.Date

 

But the display is shown in 'dd/MM/yyyy hh:mm:ss a' format.

So, for a test, I changed the DataFormatString to be '{0:dd MMM yy}', the display is still in 'dd/MM/yyyy hh:mm:ss a' format.

So it's totally ignoring what is setup in the coulum definition. Why?

I did set it up as a String and pass in the text, but then you can't sort it properly.

(Telerik version 2017.3.913.45)

2 Answers, 1 is accepted

Sort by
0
Ben
Top achievements
Rank 1
answered on 18 Oct 2017, 07:19 AM

Digging further, using Developer tools in IE (F12) I can see within the Sys.Application.add_init(), the RadGrid creation.

In there the _DefaultDateTimeFormat is set to "d/MM/yyyy h:mm:ss tt".

The Colum has DataFormatString set to "{0:dd/MM/yyyy}", but it's obviously not using that.

0
Ben
Top achievements
Rank 1
answered on 18 Oct 2017, 07:42 AM

This thread gave me a solution :-

https://www.telerik.com/forums/problem-with-date-formatstring

Needed to swap the DateTime Column type, to a date.

'Copy the fields into the DataTable
            Dim objRecord As New WorkOrderEntity
            For Each objField As EntityField In objRecord.Fields
 
                If objField.DataType Is GetType(DateTime) Then
                    objDataTableTemp.Columns.Add(objField.Alias, GetType(Date))
                Else
                    objDataTableTemp.Columns.Add(objField.Alias)
                End If
 
            Next
Tags
Grid
Asked by
Ben
Top achievements
Rank 1
Answers by
Ben
Top achievements
Rank 1
Share this question
or