Pergunta

I use jqGrid and my grid definition is like that:

...
colNames:['Type','Date','Message','User Name','Host'],
colModel:[{name:'type',index:'type', width:100},
{name:'date',index:'date', sorttype:'date', formatter:'date', 
  formatoptions: {newformat:'d-M-Y'}, width:100},
{name:'log',index:'log', width:200},
{name:'username',index:'username', width:50},
{name:'host',index:'host', width:50}], 
...

When I debug my coming data one of the date value (it is Number) is as follows:

1322550786997

Grid shows it like that:

29-Nov-2011

Everything is OK till this point. However when I want to sort my date column it doesn't change anything.

Any ideas?

Foi útil?

Solução

The problem is that decoding of the Unix (formatoptions: {srcformat: 'U', newformat: 'd-M-Y'}) date 1322550786997 get us 19-Dec-43879 and not 29-Nov-2011. You correct representation of the date will be the string "\/Date(1322550786997)\/" instead of the number 1322550786997.

See the demo:

enter image description here

UPDATED: You can also use the following custom formatter as a workaround

formatter: function (cellval, opts) {
    var date = new Date(cellval);
    opts = $.extend({}, $.jgrid.formatter.date, opts);
    return $.fmatter.util.DateFormat("", date, 'd-M-Y', opts);
}

It creates Date and then use original date formatter to convert it to the format 'd-M-Y'. See here the demo.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top