[英]Jquery datatable Date Column Sorting not Sorting based on recent Dates
Iam new to Jquery Using a Jquery plugin called datatables . 我是Jquery的新手,使用一个名为datatables的Jquery插件。 Here im getting a sorting issue in Date Column.
在这里,我在日期列中得到排序问题。 In my project, i want to sort column based on recent dates.
在我的项目中,我想根据最近的日期对列进行排序。 But it was sorting from top to bottom and bottom to top Can anyone help please?
但这是从上到下,从下到上排序,有人可以帮忙吗? Thanks
谢谢
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-uk-pre": function ( a ) {
var ukDatea = a.split('/');
return (ukDatea[0] + ukDatea[1] + ukDatea[2]) * 1;
},
"date-uk-asc": function ( a, b ) {
//alert(a)
//var ukDatea = a.split('/');
//if(ukDatea[2])
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
},
"date-uk-desc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
}
} );
For use this plugin, you should import the js file: 要使用此插件,您应该导入js文件:
<script type="text/javascript" src="//cdn.datatables.net/plug-ins/1.10.11/sorting/date-uk.js"></script>
and especified the column that contain the date. 并指定包含日期的列。
......
columnDefs: [
{ type: 'date-uk', targets: 0 }
]
......
Result: https://jsfiddle.net/cmedina/7kfmyw6x/31/ 结果: https : //jsfiddle.net/cmedina/7kfmyw6x/31/
If you want one example whitout extern js try... 如果您想要一个示例extern js,请尝试...
http://live.datatables.net/lorituwu/1/ http://live.datatables.net/lorituwu/1/
You can fix the sorting issue with php. 您可以使用php解决排序问题。
$mydate = strtotime($startdate);
$newformat = date('d-m-Y',$mydate);
echo '<tr>';
echo ' <td data-sort="'. $mydate .'">'.$newformat .'</td>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.