javascript - datatables sort by ticks and show date -
i'm using jquery datatable. doing ajax call server json array data:
[{"ticks":635020621354830000,"created":"20/04/13 13:42","action":"1","reference":"1444","fee":"0.6"},{"ticks":635023360450070000,"created":"23/04/13 17:47","action":"0","reference":"1503","fee":"0.6"},{"ticks":635023360461470000,"created":"23/04/13 17:47","action":"0","reference":"1505","fee":"0.6"}]
then build table javascript , call $('#mytable').datatable({...options}); want show first column "created" data, sort "ticks". how can ? reason there many entries in json array "created" field same value in "dd/mm/yy hh:mm" format (i don't want show milliseconds) , ticks different.
return ticks now, hide them. use idatasort parameter tell date column sort using hidden column.
see jsfiddle: http://jsfiddle.net/bfpmj/
in demo, click on column 0 header. column 0 values same date, table sort correctly. column 1 labels earliest/latest in agreement hidden column.
here relevant code:
jquery('#mytable').datatable( { "aocolumns": [ { "stype":"string", "bsearchable": false, "bvisible": false }, { "idatasort": 0 }, null, null, null ] } );
note first column made invisible , non-searchable. also, because of length of number, default datatables sorting wasn't working (perhaps can't handle long
of length, i'm not sure) - can see removing "stype":"string" , trying sort column 0. had change "stype" "string". assuming ticks same number of digits, shouldn't problem.
Comments
Post a Comment