#How to implement action or trigger event after reordering rows in a table

1 messages · Page 1 of 1 (latest)

stray owl
#

I want to run some code after a user is done reordering how do i achieve this? is it even possible.

honest ridgeBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

amber quartz
#

I got the same question.
@stray owl have you found a solutions?

fresh grotto
#

But I dont think that there is a function for it

amber quartz
#

I need to trigger an action when the user finish to reorder a table in a relation manager

fresh grotto
#

or maybe from this callable:

        ->reorderRecordsTriggerAction(
            fn (Action $action, bool $isReordering) => $action
                ->button()
                ->label($isReordering ? 'Disable reordering' : 'Enable reordering'),
        );
amber quartz
#

I think this helps only to customize the button that enable reordering. Am I wrong?

fresh grotto
#

1s

#
use Filament\Tables\Actions\Action;

  // ....
        ->reorderRecordsTriggerAction(
            fn (Action $action, bool $isReordering) => $action
                ->action(function () {
                  if (! $isReordering){
                    // Do something
                  }
                })
                ->button()
                ->label($isReordering ? 'Disable reordering' : 'Enable reordering'),
        );
#

I havent tried this, but its a guess

amber quartz
#

Very interesting, I will try

amber quartz
#

->reorderRecordsTriggerAction( fn (TableAction $action, bool $isReordering) => $action ->action(function ($isReordering){ if (! $isReordering) { CalculateRegistrationPointsByPosition::make('CalculateRegistrationPointsByPosition'); } } ) ->button() ->label($isReordering ? 'End reordering' : 'Reorder'), )

#

I tried this implemetation adding $reordering var inside action function but it doesn't work

#

When I click Reorder nothing happen, reordering with drag & drop doesn't start

fresh grotto
#

Then its not possible atm. I asked Dan if I can make a PR for it, I will let you know if he agrees

#

actually

#

Try this:

        ->reorderRecordsTriggerAction(
            fn (Action $action, bool $isReordering) => $action
                ->button()
                ->after(function () {
                })
                ->label($isReordering ? 'Disable reordering' : 'Enable reordering'),
        );
#

Try using the $isReordering inside the after()

amber quartz
#

We are quite there

#
->reorderRecordsTriggerAction(
                fn (TableAction $action, bool $isReordering) => $action
                    ->button()
                    ->after(function ($isReordering) {
                        if (! $isReordering) {
                            CalculateRegistrationPointsByPosition::make('CalculateRegistrationPointsByPosition');
                        }
                    })
                    ->label($isReordering ? 'Disable reordering' : 'Enable reordering'),
            )
#

With this code reordering default behavior works but it seems that this action is not executed:

#
CalculateRegistrationPointsByPosition::make('CalculateRegistrationPointsByPosition');
fresh grotto
#

Yeah, then I think it just doesn't work :/

amber quartz
#

I also tried to simplify omitting $isRecording logic:

->reorderRecordsTriggerAction(
                fn (Action $action, bool $isReordering) => $action
                    ->button()
                    ->after(function () {
                        CalculateRegistrationPointsByPosition::make('CalculateRegistrationPointsByPosition');
                    })
                    ->label($isReordering ? 'Disable reordering' : 'Enable reordering'),
            )
#

Doesn't work

#

Thanks a lot for your support 🫶🏻

#

It was my fault, my action was not correct

#

Now I need only a way to pass a parameter to a new function I just developed

#

I need to access $ownerRecord inside reorderRecordsTriggerAction()

#

it's working

#

in a very rough way but it works