Is there a way to use filament's table without passing any query, but only an array of data?

Hello, as the title says I just want to use filament table to display a set of data. But also instead of providing the query I just need to pass an array or collection of data. The current implementation of table doesn't fit to my use case since the sorting depends on a custom model attribute. Infolist comes to my mind with my use case but the aesthetic of doesn't match, so it has to be a table. I think when all else fails, I have to manually scour the filament table view components.
9 Replies
Matthew
Matthew3mo ago
Isn't your real question....how can I sort using a model attribute?
itsmejyv
itsmejyv3mo ago
how will it get a data if there's no query?
Null Keso
Null KesoOP3mo ago
What I want is I can just pass a collection of records since they have the model attribute already No, not really since as far as I know you can't really sort model attributes in filament tables since it uses the query from the table. The data provided by the attribute is a sum of points, where in which comes from a relationship data.
Bruno Pereira
Bruno Pereira3mo ago
Hi currently the table package doesnt allow external data to fill the table. It uses data from the Model it is using.
Bruno Pereira
Bruno Pereira3mo ago
Maybe you can try this package https://github.com/calebporzio/sushi to emulate a Model with your data
GitHub
GitHub - calebporzio/sushi: Eloquent's missing "array" driver.
Eloquent's missing "array" driver. Contribute to calebporzio/sushi development by creating an account on GitHub.
Matthew
Matthew3mo ago
You can definitely sort on attributes\accessors. I'm 99% sure you can sort on a summed value. Need to have a play with some code to check the exact syntax. If not, then I would add a computed column to your table, or just create a view, then the back end can handle all this for you.
Null Keso
Null KesoOP3mo ago
thanks for this, I think I've actually used this one before but I forgot the name of the package! I think sorting on attribute will only work on simple attributes. However the code for the model attribute requires a bit of comparison between sets of data then returns a score based on the comparison. It's not a simple attribute like fullname attribute where it's just concatenating first and last name.
Matthew
Matthew3mo ago
No, you 100% can do what you are trying to do. Look at aggregating relationships here: https://filamentphp.com/docs/3.x/tables/columns/relationships You can just add the ->sortable() method, and it works out the box. I've just tested it.
Null Keso
Null KesoOP3mo ago
thanks for the suggestion but I ended up using filament's table components It's only a readonly table tho
Want results from more Discord servers?
Add your server