F
Filamentβ€’2y ago
ericmp

how to sort a custom column

so i have a custom column that has only an integer value, and im wondering how to make it sortable πŸ€”
TeamWinsColumn::make('wins')->sortable() // i tried sortable() but as expected, SQLSTATE[42S22]: Column not found: 1054 Unknown column 'wins' in 'order clause'
TeamWinsColumn::make('wins')->sortable() // i tried sortable() but as expected, SQLSTATE[42S22]: Column not found: 1054 Unknown column 'wins' in 'order clause'
8 Replies
Patrick Boivin
Patrick Boivinβ€’2y ago
Is this an attribute on your model? I think you would need this column in the eloquent query for ->sortable() to work. (Could be a computed column, like select ... as wins )
ericmp
ericmpOPβ€’2y ago
is not an attribute, is a value i calculate on the way i dont want to store that the value in the db, but calculate it instead, is there alternatives? if there is no alternatives, what would u do?
Patrick Boivin
Patrick Boivinβ€’2y ago
Where does the wins data come from? DB or somewhere else?
ericmp
ericmpOPβ€’2y ago
comes from a method inside the model its a calculation of how many wins has, depending on some factors
Patrick Boivin
Patrick Boivinβ€’2y ago
Sure but ultimately, where is this information stored? How do you calculate the wins?
ericmp
ericmpOPβ€’2y ago
this calculations are shown in that view, not stored
Patrick Boivin
Patrick Boivinβ€’2y ago
Ok, not sure I understand but... One direction to explore would be to create a Sushi model just for display: https://filamentphp.com/blog/how-to-consume-an-external-api-with-filament-tables This tutorial fetches data from an external API but you could assemble it internally, according to your own business logic. All columns will be sortable.
ericmp
ericmpOPβ€’2y ago
that is interesting! thank u
Want results from more Discord servers?
Add your server