MedicOneSystems / MedicOneSystems/livewire-datatables
Json Column Filter Problem
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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