我已经加载了带有ajax响应数据的服务器端数据表,并且我有一栏显示:-成员的时间,格式为(例如5天,11小时,12分钟)。所以我想根据天数,小时数和分钟数对该列进行排序。 我无法向您展示整个代码,因为它是机密的,但我向您展示了ajax调用和表数据,如下所示:-
这是显示时间的列,我想根据日期,小时和分钟进行升序和降序排序。
<script>
$('table').DataTable({
processing: true,
serverSide: true,
responsive: true,
searching: true,
"ajax": {
url : "<?php echo site_url("getStatus") ?>",
"data":function(d){
}
},
"columnDefs": [
{
"render": function ( data, type, full, meta) {
//what should i have to do here for custom sorting. i have tried different ways but it won't work so i have removed that code.
},
}]
});
答案 0 :(得分:0)
@Divyarajsinh,
我正在使用laravel,我之前也遇到过同样的问题。希望对您有帮助。
通过添加aoColumns和订单来编辑刀片文件脚本
"processing": true,
"serverSide": true,
"searching": false,
'iDisplayLength': 10,
"bFilter" : false,
"bLengthChange": false,
"aoColumns": [
{ "bSortable": true }
],
"order": [
[0, "desc" ]
],
"ajax": {
"url": "{!! route("arrayList") !!}",
"type": "POST",
"jsonpCallback": 'jsonCallback',
"dataType": "jsonp"
}
路由文件
Route::post('arrayList', 'TestController@arrayList')->name('arrayList');
像这样编辑数组:
$arr=[
"4 days, 20 hours, 29 minutes",
"0 days, 00 hours, 14 minutes",
"4 days, 21 hours, 12 minutes",
"0 days, 00 hours, 41 minutes",
"4 days, 21 hours, 23 minutes"
];
然后将订单请求发送到您的控制器并使用排序数组功能。
$order=$request->order;
if($order[0]['dir']=='desc'){
arsort($arr);
} elseif($order[0]['dir']=='asc'){
asort($arr);
}