Repeater add new item to the top

Is it possible when adding a new repeater item to add it to the top instead of the bottom? It would be ideal if the add item button was also at the top so you don't need to scroll down then back up.
3 Replies
awcodes
awcodes7mo ago
You can override the ->addAction() to insert the new item to the beginning of the array.
John Wink
John Wink7mo ago
This should do what u want 🙂
->addAction(function (Repeater $component): void {
$newUuid = $component->generateUuid();
$items = array_merge(
[$newUuid => []],
$component->getState(),
);
$component->state($items);
$component->getChildComponentContainer($newUuid)->fill();
$component->collapsed(false, shouldMakeComponentCollapsible: false);
$component->callAfterStateUpdated();
})
->addAction(function (Repeater $component): void {
$newUuid = $component->generateUuid();
$items = array_merge(
[$newUuid => []],
$component->getState(),
);
$component->state($items);
$component->getChildComponentContainer($newUuid)->fill();
$component->collapsed(false, shouldMakeComponentCollapsible: false);
$component->callAfterStateUpdated();
})
رجل الجمبري
Thanks for your help but overriding actions is a bit over my head atm. Your example seems to add 2 items to the top and 1 to the bottom. After looking at the repeater resource view it seems the button can only be displayed under the items anyway so I guess its not the ideal solution. I may look to use a relation manager for this case. Cheers.
Want results from more Discord servers?
Add your server