diff --git a/docs-assets/app/app/Http/Livewire/TablesDemo.php b/docs-assets/app/app/Http/Livewire/TablesDemo.php index 8e567335a4..38cab397d3 100644 --- a/docs-assets/app/app/Http/Livewire/TablesDemo.php +++ b/docs-assets/app/app/Http/Livewire/TablesDemo.php @@ -1223,6 +1223,42 @@ class TablesDemo extends Component implements HasForms, HasTable ]); } + public function reordering(Table $table): Table + { + return $this->postsTable($table) + ->columns([ + TextColumn::make('title') + ->searchable() + ->sortable(), + TextColumn::make('slug'), + TextColumn::make('author.name') + ->numeric(), + TextColumn::make('status') + ->badge() + ->icon(fn (string $state): string => match ($state) { + 'draft' => 'heroicon-o-pencil', + 'reviewing' => 'heroicon-o-clock', + 'published' => 'heroicon-o-check-circle', + }) + ->color(fn (string $state): string => match ($state) { + 'draft' => 'gray', + 'reviewing' => 'warning', + 'published' => 'success', + }), + ]) + ->reorderable('rating'); + } + + public function reorderingCustomTriggerAction(Table $table): Table + { + return $this->reordering($table) + ->reorderRecordsTriggerAction( + fn (Action $action, bool $isReordering) => $action + ->button() + ->label($isReordering ? 'Disable reordering' : 'Enable reordering'), + ); + } + public function postsTable(Table $table, bool $hasSeededPosts = true): Table { User::truncate(); diff --git a/docs-assets/app/database/database.sqlite b/docs-assets/app/database/database.sqlite index 4c075d7633..94987aaee2 100644 Binary files a/docs-assets/app/database/database.sqlite and b/docs-assets/app/database/database.sqlite differ diff --git a/docs-assets/screenshots/images/dark/tables/reordering.jpg b/docs-assets/screenshots/images/dark/tables/reordering.jpg new file mode 100644 index 0000000000..44573b9ff8 Binary files /dev/null and b/docs-assets/screenshots/images/dark/tables/reordering.jpg differ diff --git a/docs-assets/screenshots/images/dark/tables/reordering/custom-trigger-action.jpg b/docs-assets/screenshots/images/dark/tables/reordering/custom-trigger-action.jpg new file mode 100644 index 0000000000..1237bd11db Binary files /dev/null and b/docs-assets/screenshots/images/dark/tables/reordering/custom-trigger-action.jpg differ diff --git a/docs-assets/screenshots/images/light/tables/reordering.jpg b/docs-assets/screenshots/images/light/tables/reordering.jpg new file mode 100644 index 0000000000..61b91ee700 Binary files /dev/null and b/docs-assets/screenshots/images/light/tables/reordering.jpg differ diff --git a/docs-assets/screenshots/images/light/tables/reordering/custom-trigger-action.jpg b/docs-assets/screenshots/images/light/tables/reordering/custom-trigger-action.jpg new file mode 100644 index 0000000000..f314b5cdf9 Binary files /dev/null and b/docs-assets/screenshots/images/light/tables/reordering/custom-trigger-action.jpg differ diff --git a/docs-assets/screenshots/schema.js b/docs-assets/screenshots/schema.js index afb4967ca9..80164558d6 100644 --- a/docs-assets/screenshots/schema.js +++ b/docs-assets/screenshots/schema.js @@ -2492,4 +2492,32 @@ export default { deviceScaleFactor: 3, }, }, + 'tables/reordering': { + url: 'tables?table=reordering', + selector: 'body', + viewport: { + width: 1080, + height: 640, + deviceScaleFactor: 3, + }, + before: async (page) => { + await page.click('.filament-icon-button') + + await new Promise((resolve) => setTimeout(resolve, 500)) + }, + }, + 'tables/reordering/custom-trigger-action': { + url: 'tables?table=reorderingCustomTriggerAction', + selector: 'body', + viewport: { + width: 1080, + height: 640, + deviceScaleFactor: 3, + }, + before: async (page) => { + await page.click('.filament-button') + + await new Promise((resolve) => setTimeout(resolve, 500)) + }, + }, } diff --git a/packages/tables/docs/10-advanced.md b/packages/tables/docs/10-advanced.md index 3a8ccfedbe..beeac91be7 100644 --- a/packages/tables/docs/10-advanced.md +++ b/packages/tables/docs/10-advanced.md @@ -1,6 +1,7 @@ --- title: Advanced --- +import AutoScreenshot from "@components/AutoScreenshot.astro" ## Pagination @@ -103,6 +104,8 @@ If you're using mass assignment protection on your model, you will also need to When making the table reorderable, a new button will be available on the table to toggle reordering. + + The `reorderable()` method accepts the name of a column to store the record order in. If you use something like [`spatie/eloquent-sortable`](https://github.com/spatie/eloquent-sortable) with an order column such as `order_column`, you may use this instead: ```php @@ -140,9 +143,6 @@ use Filament\Tables\Table; public function table(Table $table): Table { return $table - ->filters([ - // ... - ]) ->reorderRecordsTriggerAction( fn (Action $action, bool $isReordering) => $action ->button() @@ -151,6 +151,8 @@ public function table(Table $table): Table } ``` + + ## Polling table content You may poll table content so that it refreshes at a set interval, using the `$form->poll()` method: