Arūnas Kiršis
Arūnas Kiršis

Reputation: 195

Laravel DataTables change filters

Could not find a solution how to override Laravel DataTables behaviour. I have a piece of code in front end:

var columnFilter = function(columnSelector, value) {
    $('.clear-filter').removeClass('active');
    clearFilter();
    table.column(columnSelector + ':name').search(value).draw();
    console.log(value);
}

The problem here is that it gives me a query with 'LIKE' :

 (where 'column' LIKE '%value%'.)

Is there a way to override this and use EQUALS instead of like?

Thank you.

Upvotes: 0

Views: 2715

Answers (2)

Tim M.
Tim M.

Reputation: 155

I found the filterColumn function to be where the query can be customized. For example:

return DataTables::eloquent($model)
            ->filterColumn('columName', function($query, $keyword) {
                $sql = "columnName = ?";
                $query->whereRaw($sql, [$keyword]);
            })
            ->toJson();

Ref. https://github.com/yajra/laravel-datatables-docs/blob/master/filter-column.md

Upvotes: 1

Arūnas Kiršis
Arūnas Kiršis

Reputation: 195

Have not found a way to do it properately. However, managed to make workaround using regular expressions.

Upvotes: 0

Related Questions