datagrid
datagrid copied to clipboard
Problem with sorting by a 'combined' column
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; }
Hi, I have similar issue (in v6.0, in v5.7 is it OK). 'serial_number' is string (123/2019, ...)
` $grid->setDefaultSort([ 'serial_number' => 'DESC' ]); ... ->select('[p.serial_number]') ->select('CAST(RIGHT([p.serial_number], %i) AS UNSIGNED)', 4)->as('serial_number_year') ->select('CAST(LEFT([p.serial_number], %i) AS UNSIGNED)', 3)->as('serial_number_nr') ...
$grid->addColumnText('serial_number', 'Číslo') ->setSortable() ->setSortableCallback(function($fluent, $sort) { $direction = $sort['serial_number'];
Arrays::renameKey($sort, 'serial_number', 'serial_number_year');
Arrays::insertAfter($sort, 'serial_number_year', ['serial_number_nr' => $direction]);
$fluent->orderBy($sort);
}); `
I want to sort by year and next by number.
If the grid is rendered first time, sorting by sortable callback is not applied. After manual sort or after click on reset filter button is sort OK.