F
Filamentβ€’2y ago
astronomic

How can I sort a table on a custom page?

Hi, How can I sort a table on a custom page? I want the arrows to come out in the table, so that the user can sort by the column of their choice. How can I do it?
18 Replies
Patrick Boivin
Patrick Boivinβ€’2y ago
Hi @gamopa, have you tried sortable() on your columns?
TextColumn::make('year')
->label(__('Year'))
->sortable()
// ...
TextColumn::make('year')
->label(__('Year'))
->sortable()
// ...
astronomic
astronomicOPβ€’2y ago
It is an independent page, without resource I have a function render, which sends the result of a query
Patrick Boivin
Patrick Boivinβ€’2y ago
Are you using Filament's Table builder? I'm using sortable() with the Table builder on some custom pages...
astronomic
astronomicOPβ€’2y ago
no, I have created a custom page in app/filament/pages
Patrick Boivin
Patrick Boivinβ€’2y ago
How did you create your table on your custom page?
astronomic
astronomicOPβ€’2y ago
with html in views/filament/pages/custompage
Patrick Boivin
Patrick Boivinβ€’2y ago
Have you tried using the table builder? https://filamentphp.com/docs/2.x/tables/getting-started
Filament
Getting started - Table Builder - Filament
The elegant TALL stack table builder for Laravel artisans.
astronomic
astronomicOPβ€’2y ago
I'll look to see about it, sorry, I'm a newbie infilament
Patrick Boivin
Patrick Boivinβ€’2y ago
No worries! I'm also a newbie πŸ˜„
astronomic
astronomicOPβ€’2y ago
The problem is that I don't use a base query like this: protected function getTableQuery(): Builder { return Post::query(); } What I do is create the query in the render method. So I had to create the table manually
Patrick Boivin
Patrick Boivinβ€’2y ago
Can you rewrite it to use getTableQuery()?
astronomic
astronomicOPβ€’2y ago
I think not, because the query is to two tables at the same time. Then I list fields from those two tables. I did it like this because I couldn't find a way to use getTableQuery
Dan Harrin
Dan Harrinβ€’2y ago
using a relationship column?
astronomic
astronomicOPβ€’2y ago
And how would that be?
Dan Harrin
Dan Harrinβ€’2y ago
search "column relationship data" in the docs
astronomic
astronomicOPβ€’2y ago
ah ok, I understand what you are saying, but i don't know how to fix it to make it work. Thanks for everything, I'll try to solve it here and if I don't ask my partner for help. Thanks
Dan Harrin
Dan Harrinβ€’2y ago
you cant pass a query in the render method it has to be getTableQuery()
astronomic
astronomicOPβ€’2y ago
And how do I get it to list the result of these queries? $invoices = Invoice::select('client_id', \DB::raw('SUM(total) as total')) ->whereYear('invoice_date', $data['year']) ->groupBy("client_id") ->having('total', '>', 3005) ->get(); $expenses = Expense::select('supplier_id', \DB::raw('SUM(total) as total')) ->whereYear('expense_date', $data['year']) ->groupBy("supplier_id") ->having('total', '>', 3005) ->get();
Want results from more Discord servers?
Add your server