2011-06-25 259 views
5

我需要以兩種格式顯示日期,如mm/dd/yyyy和mm/dd/yyyy hh:mm:ss。我發現,我們可以在colmodeljqgrid日期排序和格式化

formatoptions: {srcformat: 'ISO8601Long', newformat: 'm/d/y'} 

formatoptions: {srcformat: 'ISO8601Long', newformat: 'm/d/y h:i:s'} 

使用formatoptions但我在jqGrid的爲MM/DD/YY獲得輸出。任何一個解決方案如何顯示mm/dd/yyyy。我需要對兩列進行排序。

在此先感謝

回答

6

您可以使用「Y」,而不是「Y」顯示年份爲「YYYY」而不是「YY」:如果你想有沒有前面的

formatter:'date', formatoptions: {srcformat:'ISO8601Long', newformat:'m/d/Y H:i:s'} 

你可以使用'n/j/Y'而不是'm/d/Y'來填充mounth和tha da中的空值(沒有0填充)。可以在格式化程序的the source code中找到'date'格式化程序支持的所有不同可能的標誌。

修訂:問題是,srcformatISO8601LongUniversalSortableDateTimeShortDate等(見the documentation的詳細信息)的短名稱只能與使用遠程網格數據datatype:'json'datatype:xml)。爲了使本地分揀工作正確,您應該使用而不是srcformat:'ISO8601Long'srcformat:'Y-m-d H:i:s'

The demo表明這種改變會使本地排序工作正確。

我認爲srcformat中的限制可能被解釋爲jqGrid中的一個錯誤。所以我建議你在the trirand forum中發佈相應的錯誤報告。然後Tony Tomov(jqGrid的開發人員)可以在jqGrid代碼中進行相應的更改。

+0

thanx oleg,但排序不會發生。我的colmodel代碼是'{name:'invdate',index:'invdate',sorttype:'date',formatter:'date',formatoptions:{srcformat:'ISO8601Long',newformat:'m/d/Y'}} ,'我的數組數據是'{id:「1」,invdate:「2007-10-01」,name:「test」}'。我錯過任何屬性嗎? – Sabarish

+0

@ user669789:現在我明白了您的主要問題,並建議您使用srcformat:'Y-m-d H:i:s''而不是srcformat:'ISO8601Long''作爲解決方法。我更新了我的答案。 – Oleg

+0

thanx其工作。 – Sabarish

0

很多很多謝謝....我試圖綁定jqgrid與遠程數據(json格式),我想顯示日期格式爲dd/mm/yyyy。 '日期',formatoptions:使用下面的選項

格式化後{srcformat: 'ISO8601Long',newformat: 'D/M/Y'}

它的工作完美。