@@ -67,6 +67,8 @@ class Grid
6767
6868 protected ?string $ orderingEntityClass = null ;
6969
70+ protected ?string $ dragAndDropOrderSourceColumnName = null ;
71+
7072 protected PaginationResult $ paginationResults ;
7173
7274 /**
@@ -461,7 +463,7 @@ public function getGridParameters(array|string|null $removeParameters = []): arr
461463 }
462464 }
463465
464- if ($ this ->getOrderSourceColumnName () !== null ) {
466+ if (! $ this -> isDragAndDrop () && $ this ->getOrderSourceColumnName () !== null ) {
465467 $ gridParameters ['order ' ] = $ this ->getOrderSourceColumnNameWithDirection ();
466468 }
467469
@@ -512,8 +514,8 @@ protected function loadRows(): void
512514 $ orderDirection = $ this ->orderDirection ;
513515
514516 if ($ this ->isDragAndDrop ()) {
515- $ orderSourceColumnName = null ;
516- $ orderDirection = DataSourceInterface::ORDER_DESC ;
517+ $ orderSourceColumnName = $ this -> dragAndDropOrderSourceColumnName ;
518+ $ orderDirection = DataSourceInterface::ORDER_ASC ;
517519 }
518520
519521 $ this ->paginationResults = $ this ->dataSource ->getPaginatedRows (
@@ -567,9 +569,15 @@ public function getValueFromRowBySourceColumnName(array $row, string $sourceColu
567569 return $ row [$ sourceColumnName ];
568570 }
569571
570- public function enableDragAndDrop (string $ entityClass ): void
572+ /**
573+ * When drag-and-drop is enabled the listing is always ordered by $orderSourceColumnName ascending,
574+ * regardless of any ordering coming from the request, so the persisted positions are never mixed up.
575+ * Pass null when the ordering is already baked into the data source query builder (legacy grids).
576+ */
577+ public function enableDragAndDrop (string $ entityClass , ?string $ orderSourceColumnName = null ): void
571578 {
572579 $ this ->orderingEntityClass = $ entityClass ;
580+ $ this ->dragAndDropOrderSourceColumnName = $ orderSourceColumnName ;
573581 }
574582
575583 public function enableMultipleDragAndDrop (): void
0 commit comments