问题
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
回答1:
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".
回答2:
Instead of trying to make the jqgrid format the date, you could instead use sql CONVERT to format it nicely before it gets put into the dataset that feeds the grid . I don't know what SQL you're using, but in SQL Server:
SELECT CONVERT(VARCHAR(19), GETDATE(), 120)
Would end up looking like
2013-05-21 10:18:39
More info on formats at
http://www.sql-server-helper.com/tips/date-formats.aspx
来源:https://stackoverflow.com/questions/16671566/jqgrid-date-time-format-not-being-applied