F
Filament4mo ago
nowak

When reordering records, how can I fetch the record that has been dragged and dropped?

The admin panel I am working on has a resource with a List page that revolves heavily around reordering records in the table with drag and drop. When reordering records, I need to run logic on the records based on the new order of the records. By overriding the reorderTable() method from vendor/filament/tables/src/Concerns/CanReorderRecords.php in my resources List page like this (I have added a sort column to my resource):
public function reorderTable(array $groupOrder): void
{
parent::reorderTable($groupOrder);

// Custom logic here
foreach ($groupOrder as $index => $recordKey) {
$record = GroupOrder::find($recordKey);

$sortValue = $record->sort;

\Log::info("Record ID: {$recordKey} has been reordered to new sort value: {$sortValue}");
}
}
public function reorderTable(array $groupOrder): void
{
parent::reorderTable($groupOrder);

// Custom logic here
foreach ($groupOrder as $index => $recordKey) {
$record = GroupOrder::find($recordKey);

$sortValue = $record->sort;

\Log::info("Record ID: {$recordKey} has been reordered to new sort value: {$sortValue}");
}
}
I can fetch the new order of my records based on the sort value, but I don't see any immediate way of getting the exact record that was grabbed. Is it possible to extrapolate this information somehow?
1 Reply
nowak
nowak4mo ago
I added a PR that introduces a feature to get the id of the dragged record when reordering tables: https://github.com/filamentphp/filament/pull/12005
GitHub
Introduce Enhanced Table Row Reordering with Dragged Record Identif...
Description This pull request introduces enhancements to the table row reordering feature within Filament by incorporating the identification of the dragged record alongside the new order of record...