Skip to content

CollectionDataTable, globalSearch(), non string values are not searchable #2992

Open
@dfischer-de

Description

@dfischer-de

Summary of problem or feature request

Non-string values are not searchable for laravel collections in global search.

Code snippet of problem

.../vendor/yajra/laravel-datatables-oracle/src/CollectionDataTable.php

protected function globalSearch(string $keyword): void
...
            foreach ($this->request->searchableColumnIndex() as $index) {
                $column = $this->getColumnName($index);
                $value = Arr::get($data, $column);
                if (! is_string($value)) {
                    continue;
                } else {
                    $value = $this->config->isCaseInsensitive() ? Str::lower($value) : $value;
                }
...
    }

Due to "continue", we leave the foreach loop and it does all non string values non searchable.
My solution:

if (is_string($value)) {
  $value = $this->config->isCaseInsensitive() ? Str::lower($value) : $value;
}

Please help me to unterstand, is this a bug or are non string values not supposed to be searchable?
Thank you!

System details

  • Operating System Ubuntu 20.04.5 LTS
  • PHP v8.2.3
  • Laravel v10.9.0
  • Laravel-Datatables v10.4.0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions