Skip to content

Commit

Permalink
Merge pull request #36 from CakeDC/feature/support-multiple-order-fields
Browse files Browse the repository at this point in the history
feat: support multiple order fields
  • Loading branch information
arodu authored Jun 22, 2024
2 parents fce398c + abaccf7 commit 615f286
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Controller/Component/DatatablesPaginatorComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\Controller\Component\PaginatorComponent;
use Cake\Datasource\ResultSetInterface;
use Cake\Http\ServerRequest;
use Migrations\ConfigurationTrait;

/**
* DatatablesPaginator component
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 615f286

Please sign in to comment.