Skip to content

[Bug]: Changing 'Per Page' Dropdown on Non-First Page Shows 0 Results  #1946

@red-cruz

Description

@red-cruz

What happened?

The issue arises when changing the "Per Page" dropdown value after navigating to a different page.
Specifically:

  1. I navigated to page 2 of my data table.
  2. I changed the "Per Page" dropdown value to something other than the default (10).
  3. The table displayed 0 results when it should have shown the correct set of paginated data.

How to reproduce the bug

  1. Navigate to page 2 of the data table.
  1. Change the "Per Page" dropdown value from 10 to 25.
  1. The table displays 0 results.

Package Version

3.4.20

PHP Version

8.3.x

Laravel Version

11.9

Alpine Version

No response

Theme

Bootstrap 4.x

Notes

  • Manually removing page=2& from the URL allows the table to display the correct results.
  • I have a total of 14 rows

My Component

namespace App\Livewire\Datatables\Admin;

use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\Views\Columns\ButtonGroupColumn;
use Rappasoft\LaravelLivewireTables\Views\Columns\ImageColumn;
use Rappasoft\LaravelLivewireTables\Views\Columns\LinkColumn;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateRangeFilter;

class UsersTable extends DataTableComponent
{
  protected $model = User::class;

  public function configure(): void
  {
    $this->setPrimaryKey('id');
    $this->setSingleSortingDisabled();
    $this->setLoadingPlaceholderStatus(true);
  }

  public function columns(): array
  {
    return [
      Column::make('id')->hideIf(true)->eagerLoadRelations(),
      ImageColumn::make('Profile')->location(fn($row) => $row->profile_url)->attributes(
        fn($row) => [
          'class' => 'rounded-circle border border-primary',
          'style' => 'object-fit: cover; width: 32px; height: 32px;',
          'loading' => 'lazy',
        ]
      ),
      Column::make('Role', 'role')->sortable()->searchable()->excludeFromColumnSelect(),
      Column::make('Username', 'username')->sortable()->searchable()->excludeFromColumnSelect(),
      Column::make('Email', 'email')->sortable()->searchable(),
      Column::make('Joined At', 'created_at')->sortable()->searchable(),
      ButtonGroupColumn::make('Actions')->buttons([
        LinkColumn::make('Visit') // make() has no effect in this case but needs to be set anyway
          ->title(fn() => '<i class="fa-solid fa-user-pen"></i>')
          ->location(fn($row) => route('profile', $row))
          ->attributes(function ($row) {
            return [
              'class' => 'btn btn-sm btn-primary mb-1',
              'wire:navigate' => true,
            ];
          })
          ->html(),
      ]),
    ];
  }

  public function filters(): array
  {
    return [
      DateRangeFilter::make('Join date')
        ->config([
          'allowInput' => true,
          'altFormat' => 'F j, Y',
          'placeholder' => 'Enter Date Range',
        ])
        ->filter(function (Builder $builder, array $dateRange) {
          $builder->whereDate('users.created_at', '>=', $dateRange['minDate'])->whereDate('users.created_at', '<=', $dateRange['maxDate']);
        }),
    ];
  }
}

Error Message

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions