fix: ignore table sort while its column is toggled hidden

This commit is contained in:
dualfroz committed 2026-10-10 12:44:36 +02:00
1 parent c4540cd302
commit 71ab17f6f2
3 files changed
+26 -2

No files matched your search

@@ -89,7 +89,8 @@ trait CanSortRecords
if (
$tableSortColumn &&
$column = $this->getTable()->getSortableVisibleColumn($tableSortColumn)
($column = $this->getTable()->getSortableVisibleColumn($tableSortColumn)) &&
(! $column->isToggledHidden())
) {
$sortDirection = $this->getTableSortDirection() === 'desc' ? 'desc' : 'asc';
+3 -1
View File
@@ -86,7 +86,9 @@ class UsersTable extends Component implements HasActions, HasSchemas, Tables\Con
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('posts_count')
->counts('posts'),
->counts('posts')
->sortable()
->toggleable(),
]);
}
+21
View File
@@ -239,6 +239,27 @@ describe('rendering and sorting', function (): void {
->sortTable('author.json.bar.baz', 'desc')
->assertCanSeeTableRecords($sortedDesc, inOrder: true);
});
it('ignores the sort of a `counts()` column while it is toggled hidden', function (): void {
$users = collect([3, 1, 2])->map(
fn (int $postsCount): User => User::factory()
->has(Post::factory()->count($postsCount))
->create(),
);
$component = livewire(UsersTable::class)
->sortTable('posts_count')
->assertCanSeeTableRecords([$users[1], $users[2], $users[0]], inOrder: true)
->toggleAllTableColumns(false);
expect($component->instance()->getFilteredSortedTableQuery()->toSql())
->not->toContain('posts_count');
$component
->assertCanSeeTableRecords($users, inOrder: true)
->toggleAllTableColumns()
->assertCanSeeTableRecords([$users[1], $users[2], $users[0]], inOrder: true);
});
});
describe('searching', function (): void {