|
13 | 13 | use Shopsys\AdministrationBundle\Component\Datagrid\Adapter\AdapterInterface; |
14 | 14 | use Shopsys\AdministrationBundle\Component\Datagrid\Adapter\EntityClassAwareAdapterInterface; |
15 | 15 | use Shopsys\AdministrationBundle\Component\Datagrid\Field\FieldDescriptor; |
| 16 | +use Shopsys\FrameworkBundle\Component\Grid\DataSourceInterface; |
16 | 17 | use Shopsys\FrameworkBundle\Component\Grid\GridFactory; |
17 | 18 | use Shopsys\FrameworkBundle\Component\Grid\GridView; |
18 | 19 | use Shopsys\FrameworkBundle\Component\Grid\Ordering\Exception\EntityIsNotOrderableException; |
19 | 20 | use Shopsys\FrameworkBundle\Component\Grid\Ordering\OrderableEntityInterface; |
| 21 | +use SortDirection; |
20 | 22 | use Symfony\Component\OptionsResolver\OptionsResolver; |
21 | 23 |
|
22 | 24 | /** |
@@ -45,7 +47,7 @@ final class Datagrid |
45 | 47 | private array $fieldsOrder = []; |
46 | 48 |
|
47 | 49 | /** |
48 | | - * @var array{field: string, order: \Shopsys\AdministrationBundle\Component\Datagrid\OrderingEnum}|null |
| 50 | + * @var array{field: string, order: \SortDirection}|null |
49 | 51 | */ |
50 | 52 | private ?array $defaultOrder = null; |
51 | 53 |
|
@@ -116,7 +118,7 @@ public function setPagination(bool $pagination): self |
116 | 118 | /** |
117 | 119 | * Set default order of datagrid |
118 | 120 | */ |
119 | | - public function setDefaultOrder(string $field, OrderingEnum $order): self |
| 121 | + public function setDefaultOrder(string $field, SortDirection $order): self |
120 | 122 | { |
121 | 123 | if ($this->dragAndDropEntityClass !== null) { |
122 | 124 | throw new InvalidArgumentException( |
@@ -164,7 +166,7 @@ public function enableDragAndDrop(string $field): self |
164 | 166 | $this->dragAndDropEntityClass = $entityClass; |
165 | 167 | $this->defaultOrder = [ |
166 | 168 | 'field' => $field, |
167 | | - 'order' => OrderingEnum::ASC, |
| 169 | + 'order' => SortDirection::Ascending, |
168 | 170 | ]; |
169 | 171 |
|
170 | 172 | return $this; |
@@ -303,7 +305,13 @@ public function createView(): GridView |
303 | 305 | } |
304 | 306 |
|
305 | 307 | if ($this->dragAndDropEntityClass === null && $this->defaultOrder !== null) { |
306 | | - $grid->setDefaultOrder($this->defaultOrder['field'], $this->defaultOrder['order']->value); |
| 308 | + $grid->setDefaultOrder( |
| 309 | + $this->defaultOrder['field'], |
| 310 | + match ($this->defaultOrder['order']) { |
| 311 | + SortDirection::Ascending => DataSourceInterface::ORDER_ASC, |
| 312 | + SortDirection::Descending => DataSourceInterface::ORDER_DESC, |
| 313 | + }, |
| 314 | + ); |
307 | 315 | } |
308 | 316 |
|
309 | 317 | if (count($this->fieldsOrder) > 0) { |
|
0 commit comments