© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•15mo ago•
4 replies
Lloyd

TableWidget will not sort with getStateUsing

Hi all,

I can't seem to sort my data when I am populating it with getStateUsing under a column that isn't in the model, here is my code:

                TextColumn::make('matches')
                    ->label('Matches')
                    ->getStateUsing(function ($record) {
                        $matchCount = Matches::join('books', 'books.owner', '=', 'author.id')
                            ->join('author_info', 'books.id', '=', 'author_info.host_id')
                            ->where('author_info.prefix', '=', $record->prefix)
                            ->count();

                        return $matchCount;
                    })
                    ->sortable()
            ])
            ->defaultSort('matches', 'desc');
                TextColumn::make('matches')
                    ->label('Matches')
                    ->getStateUsing(function ($record) {
                        $matchCount = Matches::join('books', 'books.owner', '=', 'author.id')
                            ->join('author_info', 'books.id', '=', 'author_info.host_id')
                            ->where('author_info.prefix', '=', $record->prefix)
                            ->count();

                        return $matchCount;
                    })
                    ->sortable()
            ])
            ->defaultSort('matches', 'desc');


The data is there, and is returning what I am expecting it to return. Even if I try and sort manually using the UI, it is not working. Can someone please help me? Thanks in advance : )

Note, this isn't in my model
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

TableWidget
FilamentFFilament / ❓┊help
3y ago
TableWidget modal not opening
FilamentFFilament / ❓┊help
3y ago
Sortable() and getStateUsing
FilamentFFilament / ❓┊help
3y ago
TableWidget interactions with livewire events.
FilamentFFilament / ❓┊help
3y ago