fibtegis/filament-infinite-scroll
Installation:
composer require fibtegis/filament-infinite-scroll
The package is auto-discoverable, so no additional configuration is needed in config/filament.php.
First Use Case:
Replace pagination in a Filament table with infinite scroll by adding the ->infinite() method to your table definition:
use Fibtegis\FilamentInfiniteScroll\InfiniteScroll;
public function table(Table $table): Table
{
return $table
->columns([
// Your columns...
])
->infinite(); // Enable infinite scroll
}
Where to Look First:
InfiniteScroll class).Basic Integration:
$table->infinite()->paginate(10); // Default batch size (adjustable)
Dynamic Batch Sizing:
$table->infinite()->paginate(20); // Larger batches for faster loading
Relation Managers:
public static function form(Form $form): Form
{
return $form->schema([
// ...
Tables\RelationManagers\PostsRelationManager::make()->table(function (Table $table) {
return $table->infinite();
}),
]);
}
Widgets:
public function getWidgets(): array
{
return [
Widgets\StatsOverviewWidget::class,
Widgets\InfiniteScrollWidget::class, // Hypothetical custom widget
];
}
Customizing Scroll Behavior:
Override the default InfiniteScroll class to modify:
// app/Providers/Filament/InfiniteScrollServiceProvider.php
public function register()
{
$this->app->bind(
InfiniteScroll::class,
fn () => new CustomInfiniteScroll()
);
}
Hybrid Approach: Combine with pagination for small datasets:
$table->infinite()->paginate(5)->when(
request()->has('page'),
fn () => $table->paginate(5)
);
Performance with Large Datasets:
limit in queries).limit() or take():
$table->query(fn (Builder $query) => $query->limit(1000)); // Hard cap
Stale Data on Filter Changes:
use Fibtegis\FilamentInfiniteScroll\InfiniteScroll;
public function actionCustomFilter()
{
return Action::make('Filter')
->action(fn () => InfiniteScroll::reset());
}
Theme Conflicts:
$table->infinite()->theme('dark'); // Explicitly set theme
Livewire Hooks Interference:
updated) may conflict with infinite scroll’s event listeners.->infinite():
$table->infinite()->hook('updated', fn () => /* ... */);
Check Network Requests:
F12) and monitor the Livewire tab for infinite scroll requests. Look for:
wire:click events triggering new batches.cursor or per_page params).Log Query Parameters: Add this to your table to inspect pagination params:
$table->infinite()->hook('render', fn () => \Log::debug(
'Infinite Scroll Params:',
request()->query()
));
Disable Infinite Scroll Temporarily: Use a feature flag to toggle infinite scroll for debugging:
$table->when(
config('filament.enable_infinite_scroll'),
fn () => $table->infinite()
);
Custom Loading States: Override the default loading spinner by publishing the package’s assets:
php artisan vendor:publish --tag=filament-infinite-scroll-assets
Then customize resources/views/vendor/filament-infinite-scroll/loading.blade.php.
Server-Side Batch Processing:
Use the InfiniteScroll::batch() method to customize how batches are fetched:
$table->infinite()->hook('batch', fn (Builder $query, int $page) => {
return $query->where('active', true)->orderBy('created_at')->take(15);
});
Scroll Threshold Adjustment: Modify the scroll percentage that triggers the next batch:
// In a service provider:
$this->app->singleton(InfiniteScroll::class, fn () => new class extends InfiniteScroll {
protected int $scrollThreshold = 90; // Default is 80
});
Integration with Filament Actions: Ensure actions work seamlessly by resetting the scroll after execution:
public static function getActions(): array
{
return [
Action::make('Delete')
->action(fn (Table $table) => InfiniteScroll::reset())
->requiresConfirmation(),
];
}
How can I help you explore Laravel packages today?