laravel-enso/tables

Table pagination fails when multi-select filters are applied

robbykrlos opened this issue · 10 comments

This is a bug.

Prerequisites

  • Are you running the latest version?
  • [?] Are you reporting to the correct repository?
  • Did you check the documentation?
  • Did you perform a cursory search?

Description

When dealing with multiple selection filters, I noticed that pagination is not working when selecting as many options as it needs to exceed the number of entries per page.

image

Steps to Reproduce

  1. Define a "<select-filter multiple ... " for one existing table
  2. Link a source (options) and a v-model.
  3. Make sure table has more entries then the result per page table setting.
  4. Select all possible options from filter.

Expected behavior

See all results as if filter was not applied with correct number of pages.

Actual behavior

Just first page is visible.

LE: tested with only one filter without multiple option, and behavior is the same.

@robbykrlos could you please write your TableBuilder & request class here?

Also (if you want I can open another ticket) the counter seems to count soft-deleted entries, showing 2 pages, but if I click page 2 - is basically empty (because it can be that only 10 are not deleted, and 10 are deleted) and it loads again page 1.

LE: this i found on a simple one table with one foreign_id to another model.

@robbykrlos could you please write your TableBuilder & request class here?

Sorry, I think I'm wasting your time. I answered initially with another example thinking will simplify things but it seems that with this new simple example it was working. So it means that maybe the problem lies into the builder where the SQL has something like:

return Virtual::with('pool')->selectRaw('
            lb_virtuals.id,
            lb_virtuals.name as virtualName,
            GROUP_CONCAT(DISTINCT lb_profiles.name) as "profileName",
            lb_virtuals.ip,

...  lot of fields....

6x left joins

->groupBy(
                'lb_virtuals.name'
            );

so maybe if you still want to pursue this, try to have something similar. If not, I'll dig deeper into it and try to find some better explanations. until then we can close this ticket.

Hi,
The pagination fails because the count() method used in vendor/laravel-enso/tables/src/Services/Data/Builders/Meta.php at line 65 fails when applied on a query which contain a groupBy clause.
In short, a count(*) on a grouped query will return the number of items that belong to each group, in your case @robbykrlos this was 1 instead of the actual number of records filtered. On the other hand, an Eloquent count() doesn't know about your query, just tells you the number of rows that were returned.

In order to fix this behavior, one must add
$this->query->get()->count() instead of
$this->query->count()

@raftx24 Can you please check this and maybe fix it in the future releases?
Thank you!

@raftx24 would you like me to make a contribution and ask for a MR? is this solution OK for you?

Hey @robbykrlos and @adithewonderboy , sorry for answering late.
this solution isn't perfect because it has a huge impact on big tables.
we should find a better solution for fixing such queries.

I guess return $this->query->getQuery()->getCountForPagination(); in Meta.php will fix it but I need to discuss with adrian.

@raftx24 I tested my case with return $this->query->getQuery()->getCountForPagination(); and it works nicely.
I hope you can push this fix soon, thanks!

please check it again it should be fixed