Sorting a columm date
- Single Page
Posted 09 October 2012 - 16:54 PM
Sorting a columm date in the format d/m/Y, the ordenation is made only for days.
example:
date
01/10/2012
03/09/2012
04/10/2012
08/11/2011
[color=#282828][font=helvetica, arial, sans-serif]Please help me to solve this problem.[/font][/color]
Posted 09 October 2012 - 19:55 PM
Posted 15 October 2012 - 19:27 PM
Posted 16 October 2012 - 06:00 AM
day | month | year
10 12 2012
Posted 18 October 2012 - 18:41 PM
i resolved with callback_collumn
function _date($value, $row)
{
return "<span style='visibility:hidden;display:none;'>".date('Y-m-d H:i:s', strtotime($value))."</span>".date('d/m/Y H:i:s', strtotime($value)).";
}
wasn't more correct, but worked
Thanks for help
Posted 18 October 2012 - 18:46 PM
It's a good solution))
Posted 17 September 2013 - 09:03 AM
Hi, it's coming late.
but try to add in datatables.js :
$.fn.dataTableExt.aTypes.unshift( function ( sData ) { var reg=new RegExp("(0[0-9]|[12][0-9]|3[01])/(0[0-9]|1[012])/(00|19|20|21)[0-9]{2}","g"); if (sData.match(reg)) { return 'uk_date'; } else { } return null; } ); $.fn.dataTableExt.oSort['uk_date-asc'] = function(a,b) { var ukDatea = a.split('/'); var ukDateb = b.split('/'); var x = parseInt(ukDatea[2] + ukDatea[1] + ukDatea[0]); var y = parseInt(ukDateb[2] + ukDateb[1] + ukDateb[0]); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }; $.fn.dataTableExt.oSort['uk_date-desc'] = function(a,b) { var ukDatea = a.split('/'); var ukDateb = b.split('/'); var x = parseInt(ukDatea[2] + ukDatea[1] + ukDatea[0]); var y = parseInt(ukDateb[2] + ukDateb[1] + ukDateb[0]); return ((x < y) ? 1 : ((x > y) ? -1 : 0)); };
and this callback function in your controller on the date field
public function _callback_date($value, $row) { $date = explode("-",$value); return $date[2]."/".$date[1]."/".$date[0]; }
Posted 12 November 2013 - 19:15 PM
+1 for Rafael Alves's solution: should be part of grocery CRUD (as an optional feature)
(Didn't tested Patos's solution since I don't want to modify Grocery CRUD files, but could be good as well)
Posted 21 November 2013 - 13:35 PM
Rafael Alves's solution would have an issue on export function. The span code will appear in the exported xls file
Posted 16 August 2014 - 14:52 PM
@Rafael Alves : it works great, thanks !