vedmack / yadcf

Yet Another DataTables Column Filter (yadcf)
http://yadcf-showcase.appspot.com/
MIT License
731 stars 285 forks source link

DataTables server-side (yajra) + yadcf (data_range filter does not display any data) #622

Closed phuthoma closed 4 years ago

phuthoma commented 4 years ago

I'm using Datatables in server-side mode (powered with https://github.com/yajra/laravel-datatables) with custom paging, ordering and searching - I'm just passing the results based on data sent by DataTables to server at each draw - so I'm not loading the entire table.

YADCF text filters works fine, but data_range filters don't and I don't know how to make them work.

Here's my controller code:

public function injectQuery($query, $request, $columns) {
    // other filters logic

    // date_range filter logic
    if (!empty($request['columns'][7]['search']['value'])) {
        $date = $request['columns'][7]['search']['value'];
        $date = explode('-yadcf_delim-', $date);
        $min_date = $date[0];

        if ($date && sizeof($date) > 1) {
            $max_date = $date[1];
        }

        if ($min_date)
            $query->whereDate($request['columns'][7]['name'], '>=', $min_date); 

        if ($max_date)
            $query->whereDate($request['columns'][7]['name'], '<=', $max_date); 
    }

    return $query;   
}

public function getDataTablesJsonActivities(Request $request) { 
    $query = Activity::query();  
    $columns = $request['columns'];

    return DataTables::of($query)     
        ->filter(function($query) use ($columns, $request) {
            $query = $this->injectQuery($query, $request, $columns);
        }, true)
        ->toJson();
}

Laravel query result seems to be OK, but no data is populated to Datatables. Here are some videos for more details: https://streamable.com/pjz41s https://streamable.com/ibyljl

The problem seems to be caused by YADCF, which is sending it's date value (with custom delimiter) to query bindings:

json

Perhaps there is way to disable YADCF filtering for this column?

System details