diff --git a/src/Controller/Component/DatatablesPaginatorComponent.php b/src/Controller/Component/DatatablesPaginatorComponent.php index 2d2902b..2d2e2dc 100644 --- a/src/Controller/Component/DatatablesPaginatorComponent.php +++ b/src/Controller/Component/DatatablesPaginatorComponent.php @@ -6,6 +6,7 @@ use Cake\Controller\Component\PaginatorComponent; use Cake\Datasource\ResultSetInterface; use Cake\Http\ServerRequest; +use Migrations\ConfigurationTrait; /** * DatatablesPaginator component @@ -52,12 +53,28 @@ protected function applyOrder(array $data, array $settings): array continue; } $colName = $dtColumns[$colIndex]['data']; - $settings['order'][$colName] = $colOrder; + + $settings['order'] = array_merge($settings['order'] ?? [], $this->filterOrder($colName, $colOrder)); } return $settings; } + /** + * @param string $colName + * @param string $colOrder + * @return array + */ + protected function filterOrder(string $colName, string $colOrder): array + { + $filters = $this->getConfig('filterOrder') ?? []; + if (isset($filters[$colName])) { + return array_fill_keys($filters[$colName] ?? [], $colOrder); + } + + return [$colName => $colOrder]; + } + /** * Translate limit and offset from datatables *