rappasoft / laravel-livewire-tables

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

Select All Issue on Big Data (>130k records) in Table #1827

Closed nisar2112 closed 1 month ago

nisar2112 commented 1 month ago

What happened?

When I click on "Select All" for a table with more than 130,000 records, the table fails. The issue occurs because the frontend sends all the IDs to the backend in an update array within the request. This causes the process to fail and the page to become unresponsive.

I reviewed the documentation and found a previous issue discussing this problem. The suggested solution was to use the following function: $this->setDelaySelectAllEnabled();

However, when I attempted to apply this function, I encountered an error: setDelaySelectAllEnabled does not exist.

How to reproduce the bug

No response

Package Version

3.2 i update that v to v3.4.2 and that setDelaySelectAllEnabled does not exist. error is not show but its stuck on frontend as you can see in below picture.

PHP Version

8.1.x

Laravel Version

10.7

Alpine Version

No response

Theme

None

Notes

No response

Error Message

image as its show update request is return 200 but frontend is stuck No response

ilsyaa commented 1 month ago

I have a solution by giving the maximum that can be selected

nisar2112 commented 1 month ago

I have a solution by giving the maximum that can be selected

can you please help me to solve that ?

lrljoe commented 1 month ago

There was a new feature introduced in 3.4.0 that tackles this issue natively see PR #1810 for details

nisar2112 commented 1 month ago

image image

check that picture i try version 3.4.0 and also 3.4.2 and before trying that i delete my publish files too but its still not work with my configure function

image

nisar2112 commented 1 month ago

my page is not responding after click select all.

ilsyaa commented 1 month ago

in my case i have 30k data Screenshot 2024-08-07 155827 code

lrljoe commented 1 month ago

In future, please share code wrapped in three ` marks, rather than screenshots

Your issue is in your configure method, namely, you've added these two methods into it:

   $this->setSelectAllStatus(true);
   $this->setSelectAllEnabled();

These two override the setDelaySelectAllEnabled(). They tell the Table to populate the selected array with ALL primary keys, EVERY LIFECYCLE, regardless of what the end-user selects. Remove them, and give it a test.

nisar2112 commented 1 month ago
    public function configure(): void
    {
        $this->setPrimaryKey('id');
        $this->setSearchDebounce(800);
        $this->setReorderDisabled();
        $this->setPerPageAccepted([50, 100, 150, 200]);
        $this->setDefaultSort('created_at', 'desc');
        $this->setPaginationEnabled();
        $this->setFilterLayoutSlideDown();
        $this->setDelaySelectAllEnabled(); // here i add that
        $this->setThAttributes(function (Column $column) {
            if ($column->isField('final_amount')) {
                return [
                    'class' => 'd-flex justify-content-end',
                ];
            }
            if ($column->isField('amount')) {
                return [
                    'class' => 'text-end',
                ];
            }

            return [
                'class' => 'text-center',
            ];
        });

        $this->setTdAttributes(function (Column $column, $row, $columnIndex, $rowIndex) {
            if (in_array($column->getField(), ['status', 'id'])) {
                return [
                    'class' => 'text-center',
                ];
            }
            if (in_array($column->getField(), ['final_amount', 'amount'])) {
                return [
                    'class' => 'text-end',
                ];
            }

            return [];
        });
    }

check it i try with this setting its still stuck complete page and not responding when i click on select ALL Then that update event is fire and its return status = 200 in 6 seconds but page is stuck

lrljoe commented 1 month ago

Make sure that you've run "npm run build", and have cleared out published views.

I'll test it again this week, but it was definitely working when I tested it before pushing the update out.

So you're clicking on "Select All", is it then hanging, or is hanging after you pick a Bulk Action?

nisar2112 commented 1 month ago

I also did this step (Make sure that you've run "npm run build", and have cleared out published views) after that when i click "Select All" then hang that table page and i can't click on anything

lrljoe commented 1 month ago

I also did this step (Make sure that you've run "npm run build", and have cleared out published views) after that when i click "Select All" then hang that table page and i can't click on anything

And which theme are you using plz, tailwind, bootstrap4 or bootstrap5

nisar2112 commented 1 month ago

bootstrap5

lrljoe commented 1 month ago

bootstrap5

Thanks, I'll spin up a test instance, as there may be something not present in the bs5 frontend code

lrljoe commented 1 month ago

And just to confirm, you're clicking on the words, select all, not the checkbox on the top left?

nisar2112 commented 1 month ago

yes thank you for that issue is when i click on that checkbox for select all its hanging and when i click "select all" that word button its work correctly on 130k data

nisar2112 commented 1 month ago

one thing more when i click on "select all" that word its select all checkbox on first page which show and when i change to next page that checkbox is not show as checked and also if i click on bulk action and do one action like delete its deleting records slowly not all at once is that possible to handle this 2 case too

lrljoe commented 1 month ago

If you click on the words select all, that's when the delay select all behaviour kicks in.

So if you have a bulk action that just dumps the data (e.g. dds it) Or if you have a bulk action that deletes all selected rows, then that is when it comes into play

In your bulk action using the aforementioned extra handler to get all selected rows, it will return all selected rows, so long as you haven't navigated etc

I can look at setting the checkboxes on subsequent pages to be checked BUT unchecking the boxes would have no effect, unless you use the traditional behaviour (not delaySelect)

In terms of it being slow in a bulk action, what is your bulk action doing, if it is deleting in a foreach loop, then yes, that will be very slow, and that's a PHP thing.

nisar2112 commented 1 month ago

yes now its work with delete i change foreach to array_chunk its work to delete all records of total 82747 at 59 seconds

nisar2112 commented 1 month ago

after selecting all and that total records is show but when we unselect some then that unselect is not subtracting from total

lrljoe commented 1 month ago

after selecting all and that total records is show but when we unselect some then that unselect is not subtracting from total

Yep, that's how the delay select works for now.

Either use the standard approach which lets you deselect, or use the delaySelect if you don't need to deselect.

Otherwise, what you're asking for is an array to be populated with all of the IDs, so that you can deselect some, but then you don't want the array to be populated as it takes too long.

Not sure how best to tackle that to be honest! Short of adding possible items as you paginate, and removing any items that you didn't select. But that feels like it'd be slow.