yajra / laravel-datatables

jQuery DataTables API for Laravel
https://yajrabox.com/docs/laravel-datatables
MIT License
4.75k stars 861 forks source link

Searching on field which has a numeric and string value in a STRING field #3176

Closed Roydee closed 1 week ago

Roydee commented 1 week ago

Summary of problem or feature request

So i have a field titled 'default_due_date_label' in my database which carries data such as this:

The 'default_due_date_label' is a STRING field.

Search 1: When I perform a search for example "6 Months Before" it does NOT return any results. Search 2: However if I search on "Months Before" it returns all results which has this search term.

It seems to leaving out the numeric value in Search 1.

Spend lots of hours on this so far and I am wondering if someone could help me out.

Code snippet of problem

While the code below should not be needed. I have also tried it.

->filterColumn('default_due_date_label', function ($query, $keyword) { // Perform a case-insensitive search for the entire keyword $query->whereRaw('LOWER(default_due_date_label) LIKE ?', ['%' . strtolower($keyword) . '%']); })

System details

yajra commented 1 week ago

It could be due to the multi-term search config. Try disabling it in the datatables.php config.

'multi_term' => false,
Roydee commented 1 week ago

Perfect... thats worked. Thanks so much.