MedicOneSystems / MedicOneSystems/livewire-datatables

Json Column Filter Problem

Open
#318 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.2k
Forks
257
PR merge metrics
No merged PRs in 30d

Description

Hi
Thank you for this awesome package
I just wanted to mention here that I have noticed an error with addTextFilters function query regarding json columns.

in LivewireDatatable.php I added the + signed code

public function addTextFilters()
{
        if (!count($this->activeTextFilters)) {
            return $this;
        }
        $this->query->where(function ($query) {
            foreach ($this->activeTextFilters as $index => $activeTextFilter) {
                $query->where(function ($query) use ($index, $activeTextFilter) {
                    foreach ($activeTextFilter as $value) {
                        if ($this->columnIsRelation($this->freshColumns[$index])) {
                            $this->addAggregateFilter($query, $index, $activeTextFilter);
                        } else {
                            $query->orWhere(function ($query) use ($index, $value) {
                                foreach ($this->getColumnFilterStatement($index) as $column) {
                                    $column = is_array($column) ? $column[0] : $column;
                                  + if (Str::contains($column, '->')) {
                                  +    $column = explode('->', $column);
                                  +    $column = $column[0].'->"$.'.$column[1].'"';
                                  +  }
                                    $query->orWhereRaw('LOWER(' . $column . ') like ?', [mb_strtolower("%$value%")]);
                                }
                            });
                        }
                    }
                });
            }
        });

        return $this;
}

now it works efficiently

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in LivewireDatatable.php at addTextFilters(), then trace getColumnFilterStatement() for JSON column values. Reproduce the reported filtering problem and compare it with the workaround shown in the issue; done means JSON-column text filters work without requiring that local modification.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
backend, databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.