vedmack / yadcf

Yet Another DataTables Column Filter (yadcf)

Home Page:http://yadcf-showcase.appspot.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

phuthoma opened this issue · comments

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

  • Operating Syste: Ubuntu 16.04 LTS
  • PHP Version: 7.3.16
  • Laravel Version: 5.5.48
  • Datatables Version: 1.10.20
  • Laravel-Datatables Version (yajra): 8.13.7
  • YADCF Version: 0.9.3