change datatable to accept multisort

This commit is contained in:
2024-12-23 07:50:36 +00:00
parent dbbc25ac7b
commit e9ca94f089
2 changed files with 13 additions and 5 deletions

View File

@@ -57,12 +57,17 @@ class DataTableInput
} }
/** /**
* @return Sort|null * @return array|null
*/ */
public function getSorting(): ?Sort public function getSorting(): ?array
{ {
return !empty($this->sorting) ? $sorts = [];
new Sort($this->sorting[0]->id, $this->sorting[0]->desc, $this->allowedSortings) : null; if (!empty($this->sorting)){
foreach ($this->sorting as $sort) {
$sorts[] = new Sort($sort->id, $sort->desc, $this->allowedSortings);
}
}
return $sorts == [] ? null : $sorts;
} }
public function getRelations(): array public function getRelations(): array

View File

@@ -83,7 +83,10 @@ class DataTableService
} }
$sorting = $this->dataTableInput->getSorting(); $sorting = $this->dataTableInput->getSorting();
$query = (new ApplySort($query, $sorting))->apply(); foreach ($sorting as $sort){
$query = (new ApplySort($query, $sort))->apply();
}
return $query; return $query;
} }