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]: Per Page doesn't apply when returning to the table #1654

Closed tjhunkin-inhance closed 4 months ago

tjhunkin-inhance commented 4 months ago

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

lrljoe commented 4 months ago

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!

CovertError commented 4 months ago

I'm having the same issue on v3

CovertError commented 4 months ago

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

lrljoe commented 4 months ago

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

nicomitov commented 4 months ago

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);
    ...
}
lrljoe commented 4 months ago

So setting this in configure():

    $this->setPerPage(12);

Will over-ride whatever it receives in the querystring.

Effectively what is happening is:

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.

lrljoe commented 4 months ago

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.

nicomitov commented 4 months ago

setDefaultPerPage() works for me. Thanks!

tjhunkin-inhance commented 4 months ago

seems to be working fine, thanks