Update rows in table (or table) after action on row

i have custom action to reorder categories in my plugin the db is updated but the ui/table not any idea? ``` ->actions([ Tables\Actions\ActionGroup::make([ Tables\Actions\EditAction::make(), Tables\Actions\Action::make('moveUp') ->label('Move Up') ->icon('heroicon-o-chevron-up') ->color('success') ->requiresConfirmation() ->action(function (Category $record, $livewire): void { $query = Category::query() ->where('parent_id', $record->parent_id) ->where('sort_order', '<', $record->sort_order) ->orderBy('sort_order', 'desc'); if ($swapRecord = $query->first()) { $tempOrder = $record->sort_order; $record->update(['sort_order' => $swapRecord->sort_order]); $swapRecord->update(['sort_order' => $tempOrder]); } $livewire->getTableRecords()->fresh(); }), ... ])
10 Replies
toeknee
toeknee2mo ago
Just return true I believe on the end of your action and remove. the :void { off. Table actions should cause a natrual refresh of the table on action occuring.
Soundmit
SoundmitOP2mo ago
it works if i keep ->requiresConfirmation() otherwise i have to refresh the page
Tables\Actions\Action::make('moveDown')
->label('Move Down')
->icon('heroicon-o-chevron-down')
->color('success')
->requiresConfirmation()
->action(function (Category $record) {
$query = Category::query()
->where('parent_id', $record->parent_id)
->where('sort_order', '>', $record->sort_order)
->orderBy('sort_order', 'asc');

if ($swapRecord = $query->first()) {
$tempOrder = $record->sort_order;
$record->update(['sort_order' => $swapRecord->sort_order]);
$swapRecord->update(['sort_order' => $tempOrder]);
}

return true;

}),
Tables\Actions\Action::make('moveDown')
->label('Move Down')
->icon('heroicon-o-chevron-down')
->color('success')
->requiresConfirmation()
->action(function (Category $record) {
$query = Category::query()
->where('parent_id', $record->parent_id)
->where('sort_order', '>', $record->sort_order)
->orderBy('sort_order', 'asc');

if ($swapRecord = $query->first()) {
$tempOrder = $record->sort_order;
$record->update(['sort_order' => $swapRecord->sort_order]);
$swapRecord->update(['sort_order' => $tempOrder]);
}

return true;

}),
toeknee
toeknee2mo ago
@Dan Harrin is this intentional for the table to refresh only after confirmations?
Dan Harrin
Dan Harrin2mo ago
it should work as it is
Dan Harrin
Dan Harrin2mo ago
im not testing this, if you would like to submit a bug report please do
Soundmit
SoundmitOP2mo ago
uhm i can't, i don't have a public repo for this..
Dan Harrin
Dan Harrin2mo ago
you can create a new one with minimal changes to reproduce the problem
Soundmit
SoundmitOP2mo ago
I'll do it when I have time... unfortunately, I don't have any right now... I'm the only developer and I handle the project, development, testing, and deployment...
toeknee
toeknee2mo ago
That's fine, Dan has even less time at the moment I suspect. So if you get chance please do submit a report with a re-production repo.

Did you find this page helpful?