rappasoft/laravel-livewire-tables

[Bug]: Per Page doesn't apply when returning to the table

tjhunkin-inhance opened this issue · 9 comments

What happened?

select show 100 records for example, which it does, navigate away from the table, then return and the per-page remains at 100, however, the table shows the default limit. So either the per page needs to be reset when returning or it needs to display the selected amount of 100.

How to reproduce the bug

No response

Package Version

latest

PHP Version

8.2.x

Laravel Version

latest

Alpine Version

latest

Theme

Tailwind 3.x

Notes

No response

Error Message

No response

Just to confirm that you're on v3.x?

Can you try adding to a table:

    public string $tableName = 'my-random-table';

    public $my-random-table;

Just want to see if that's the issue or not!

I'm having the same issue on v3

Just to confirm that you're on v3.x?

Can you try adding to a table:

    public string $tableName = 'my-random-table';

    public $my-random-table;

Just want to see if that's the issue or not!

adding this doesn't fix it

@CovertError - can you share the content of your table component please :) as this will help me figure out what isn't correct!

I can confirm the bug.
It occurs when setPerPageAccepted() and setPerPage() are set in the table component.

e.g.:

public function configure()
{
    $this->setPerPageAccepted([12, 30, 50, 100]);
    $this->setPerPage(12);
    ...
}

So setting this in configure():

    $this->setPerPage(12);

Will over-ride whatever it receives in the querystring.

Effectively what is happening is:

  • The mount method is setting the historic "per-page" from the session (if it exists)
  • The QueryString is then updating the "per-page" (which by default with Laravel/Livewire happens in the boot step)
  • Your configure() method is then changing "per-page" to be whatever you define there.

I think the smoothest approach would be adding in a setDefaultPerPage() method, so that you can set a default, that'll apply only if it's not in the session/querystring.

I've added in a setDefaultPerPage() available in the latest release (v3.2.2).

Using setDefaultPerPage(5) (for example), will set the perPage to "5" (so long as it is in the list of allowed perPage options), IF there is not an existing value in the session/querystring.

If you use setDefaultPerPage instead of setPerPage in your configure() method, then this should resolve the issue.

setDefaultPerPage() works for me. Thanks!

seems to be working fine, thanks