jqGrid - date & time format not being applied

14,211

jqGrid have predefined formatter:"date", but no formatter:"datetime" (see the documentation). So you should fix the name of formatter to make it working.

The last version of jqGrid supports YYYY-MM-DDTHH:mm:ss and not only YYYY-MM-DD HH:mm:ss. So you don't need to make any changes on the backend.

You should consider to use sorttype: "date" instead. It could be helpful if you use loadonce: true or if you use datatype: "local".

Share:
14,211
steve_o
Author by

steve_o

Updated on June 05, 2022

Comments

  • steve_o
    steve_o almost 2 years

    I have a jqGrid that displays 3 columns, one of which is a date-time (SQL Datetime field that is being returned). The colModel settings follow:

                   colModel:[
                {name:"col1",....,sortable:false},
                {name:"col2",....,sortable:false},
                {name:"SendTime",index:"SendTime",width:col3width,align:"left",formatter:"datetime",formatoptions:{srcformat:"ISO8601Long",newformat:"LongTime"},xmlmap:"SendTime",sortable:false}
                ],
    

    The date that is being returned from SQL is in the following format:

    YYYY-MM-DDTHH:mm:ss
    

    None of the fields in the jqGrid will be sortable, and the SQL ORDER BY controls the order of the data being returned.

    I would like to change the date format that is being returned to omit the "T" in the middle of it - YYYY-MM-DD HH:mm:ss. If I can't do that, I would consider just having the formatted military time. I've tried several format options in the colModel settings, but have only succeeded in formatting the date or the time, but not both at once.

    Does this require a custom formatter, or am I overlooking settings in jqGrid? Would appreciate any help.

    Thanks! S

  • steve_o
    steve_o almost 11 years
    As noted above, I am using version 4.4.5 (current one is 4.5.2). Was there an issue with date time in the version I am using?
  • Oleg
    Oleg almost 11 years
    @steve_o: If I remind me correctly the version 4.5.0 starts support of T, but there are many ways how you can change T to space. You can use for example beforeProcessing callback to modify the data returned from the server before it will be processed by jqGrid.
  • steve_o
    steve_o almost 11 years
    This was the issue. Once I moved to the current one, all of the formatting issues I had regarding Date & Time were resolved.