datagrid icon indicating copy to clipboard operation
datagrid copied to clipboard

Documentation > Sorting

Open igorpocta2 opened this issue 7 years ago • 0 comments

Hello guys,

I found a mistake in the example source code of sorting. When you will move a penultimate record and put it behind the last record, the order will crash.

The problem is in the part 3. When the next item does not exist, there is inserted zero and all records greater or equal to zero are increased. Correctly is number of records minus one.

IMG1 IMG2

 /**
     * 3, Find all items that have to be moved one position down
     */
    $itemsToMoveDown = $repository->createQueryBuilder('r')
        ->where('r.order >= :order')
        ->setParameter('order', $nextItem ? $nextItem->getOrder() : 0)
        ->andWhere('r.order < :order2')
        ->setParameter('order2', $item->getOrder())
        ->getQuery()
        ->getResult();

    foreach ($itemsToMoveDown as $t) {
        $t->setOrder($t->getOrder() + 1);
        $this->em->persist($t);
    }

igorpocta2 avatar Apr 06 '18 13:04 igorpocta2