FilamentF
Filament13mo ago
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');


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
Was this page helpful?