rappasoft / laravel-livewire-tables

A dynamic table component for Laravel Livewire
https://rappasoft.com/docs/laravel-livewire-tables/v2/introduction
MIT License
1.7k stars 320 forks source link

[Bug]: Bulk actions tr row doesnot update when a row is selected #1563

Closed bonge-ian closed 7 months ago

bonge-ian commented 7 months ago

What happened?

I have a component that contains a datatable.

Inside the parent component, the user can select a date and when selected, an event is sent to the datatable and populates the bulk actions using the bulk actions method.

The bulk actions method:

protected $listeners = [
    'some-actions' => 'activateBulkActions',
];

public function activateBulkActions(array $data): void
{
    $this->reprocess_data = array_merge($this->reprocess_data, $data);
}

public function bulkActions(): array
  {
      if (blank($this->reprocess_data)) {
          return [];
      }

      if (
          Arr::exists($this->reprocess_data, 'activity') &&
          filled(Arr::get($this->reprocess_data, 'activity'))
      ) {
          return [
              'reprocessActivity' => 'Reprocess Activity Records',
          ];
      }

      //.....

      return [];
  }

So when the user selects a row, a row popups in the table.

librewolf_AkB5P8xGeC

The row is supposed to indicate the number of rows selected by users and allows to select all, select all on page or deselect all.

However, the row does not update nor are the actions (select all, select all on page or deselect all) don't work and are unclickable.

![Uploading librewolf_AdkB5P8xGeC.png…]()

LSpMQU0scA

How to reproduce the bug

Parent component, that has an action that emits an event to datatable component.

This then activates the bulk actions.

Select some rows. Check to see if the row updates correctly librewolf_AdkB5P8xGeC

Package Version

2.15.0

PHP Version

8.1.x

Laravel Version

10.10

Alpine Version

3.13.3

Theme

Tailwind 3.x

Notes

No response

Error Message

No response

lrljoe commented 7 months ago

Bulk Actions is designed for use within the table itself, not for listening for events, and then auto-magically populating options, and selected items etc.

Depending on your use case, it'd almost certainly be easier to use the configurable areas options to prepend/append views to your Data Table Component, rather than using events to pass back and forth (this is a direct recommendation from Livewire Core).

If you absolutely require the functionality to populate the bulk actions via events etc (noting the security risk that this can potentially present), then please develop and issue a PR, noting that I'm presently only reviewing actual bug fixes for the 2.x branch, as focus for new features is on the 3.x branch, but hope to do final releases for v2 in the coming month (from my perspective at least!).

You may have some success in removing currently published views. Noting that if you have previously published the views in an earlier version, you should always update them to match the latest version for your branch (1.x/2.x/3.x).

It is very strongly recommended to never publish the views for the tables package, as it is mostly unnecessary, due to the number of configurable options natively available, and it tends to cause issues down the line as the views are regularly updated.

bonge-ian commented 7 months ago

@lrljoe Thank you for your input.

Previous versions, before v2.15 worked.

I ended up upgrading to version 3. The highlighted problems is no more in version 3 and previous versions before 2.15.