0

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.

2
  • Why don't you ask / search on the yajra-datatable repository or their documentation site yajrabox.com/docs/laravel-datatables? Commented Oct 11, 2018 at 8:58
  • I have read all the documentation few times (not only this one), however, no solution was found. Commented Oct 11, 2018 at 12:18

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.