在yajra / datatables中是否有一种方法可以过滤和排序不在数据库中的数据? 我用addColumn创建了一个列,该列使2个日期之间有所不同,它工作正常,但我无法使用DataTable的搜索和排序功能。 可以给我小费吗?
这是Controller中的来源
public function TasksData(){
return DataTables::of(Task::query())
->editColumn('id', function(Task $task) {
$link='';
$link .= '<a href="#">'.$task->id.'</a>';
return $link;
})
->editColumn('task_id', function(Task $task) {
return $task->Task->name;
})
->editColumn('reception_date', function(Task $task) {
$date = '';
$date .= (new Carbon\Carbon($task->reception_date))->format('d/m/Y');
return $date;
})
->filterColumn('reception_date', function ($query, $keyword) {
$query->whereRaw("DATE_FORMAT(reception_date,'%d/%m/%Y') like ?", ["%$keyword%"]);
})
->editColumn('fullfilment_request', function(Task $task) {
$date = '';
$date .= (new Carbon\Carbon($task->fullfilment_request))->format('d/m/Y');
return $date;
})
->filterColumn('fullfilment_request', function ($query, $keyword) {
$query->whereRaw("DATE_FORMAT(fullfilment_request,'%d/%m/%Y') like ?", ["%$keyword%"]);
})
->addColumn('days', function(Task $task) {
$date = '';
$reception = Carbon\Carbon::parse($task->reception_date);
$fullfilment = Carbon\Carbon::parse($task->fullfilment_request);
$date .= $reception->diffInDays($fullfilment, false);
return $date;
})
->setRowClass(function (Task $task) {
$date = '';
$reception = Carbon\Carbon::parse($task->reception_date);
$fullfilment = Carbon\Carbon::parse($task->fullfilment_request);
$date .= $reception->diffInDays($fullfilment, false);
return ($date < 7 && $date == 1) ? 'bg-warning' : (($date < 0 && $date < 3) ? 'bg-danger' : '');
})
->rawColumns(['id','task_id','reception_date','fullfilment_request','days'])
->make(true);
}