Hello everyone!
Is is possible in jqGrid to display dates nicely to the user and have sorting work correctly?
Let’s say that I have three dates (in ISO 8601 format http://en.wikipedia.org/wiki/ISO_8601) :
2008-05-21T06:38:17.25+02:00
2008-05-21T19:18:10.01+02:00
2008-05-1T07:21:27.45+02:00
I would like the user to only see the following :
Today 6:38 AM
Today 7:18 PM
Three weeks ago
And assuming the user clicks on the column header, the values should then be sorted as follows (newest to oldest) :
Today 7:18 PM
Today 6:38 AM
Three weeks ago
I have read the documentation (http://trirand.com/jqgrid/docs/colmodelapi.htm) with regards to the parameters “sorttype” = date and “datefmt” = Y-m-d, however these don’t do the trick as they do not apply to the presentation of the date to the end user.
I tried to add a bit of code to the addXmlData function to manually format the dates the way I wanted them displayed, however this screws up the sort as jqGrid uses the cell text value during sorting, here :
var sortArrayData = function() {
…
} else if(st == ‘date’) {
findSortKey = function($cell) {
var fd = ts.p.colModel[column].datefmt || “Y-m-d”;
return parseDate(fd,$cell.html()).getTime();
}
So it would seem that I can either display the date nicely or have sorting working correctly but not both together.
Does anyone know of a work around? The best solution I can think of is to cache the data used to populate the grid initially and then use that to perform the sort (instead of the data actually stored in the table cells).
Any suggestions?
Thanks,
Patrick Collins
Avignon, France
PS : Here is the code that I tried to add to function addXmlData
if(ts.p.xmlReader.repeatitems===true){
$(ts.p.xmlReader.cell,this).each( function (i) {
addCell(t,row,this.textContent || this.text || ‘
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top