contributte / contributte/datagrid
Problem with sorting by a 'combined' column
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 296
- Forks
- 215
- PR merge metrics
- No merged PRs in 30d
Description
When I make a column, which combines data from two fields and use the third argument to declare those columns for filter as mentioned in documentation
$grid->addFilterText('name', 'Search', ['name', 'surname', 'company', 'address']);
then try to add sorting by such column, I get an error
Illegal offset type
on this line ($sort[$column->getSortingColumn()] = $order; in method createSorting)
I can see the method does not expect the array. I'm proposing to apply something along these lines to fix this:
$columns = is_array($column->getSortingColumn()) ? $column->getSortingColumn() : [$column->getSortingColumn()];
foreach($columns as $columnName) {
$sort[$columnName] = $order;
}
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 src/DataGrid.php at line 813, in the createSorting method, and compare its handling of getSortingColumn() with the documented addFilterText example. Reproduce sorting on a column combining name, surname, company, and address. Done means sorting no longer raises Illegal offset type when the sorting column is an array.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100