RadGrid GridDateTimeColumn ignoring DataFormatString?

3 posts, 0 answers
  1. Ben
    Ben avatar
    13 posts
    Member since:
    Aug 2015

    Posted 18 Oct 2017 Link to this post

    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. Ben
    Ben avatar
    13 posts
    Member since:
    Aug 2015

    Posted 18 Oct 2017 Link to this post

    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.

  3. Ben
    Ben avatar
    13 posts
    Member since:
    Aug 2015

    Posted 18 Oct 2017 Link to this post

    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
Back to Top