F
Filamentβ€’14mo 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β€’14mo ago
Hi @gamopa, have you tried sortable() on your columns?
TextColumn::make('year')
->label(__('Year'))
->sortable()
// ...
TextColumn::make('year')
->label(__('Year'))
->sortable()
// ...
astronomic
astronomicβ€’14mo ago
It is an independent page, without resource I have a function render, which sends the result of a query
Patrick Boivin
Patrick Boivinβ€’14mo ago
Are you using Filament's Table builder? I'm using sortable() with the Table builder on some custom pages...
astronomic
astronomicβ€’14mo ago
no, I have created a custom page in app/filament/pages
Patrick Boivin
Patrick Boivinβ€’14mo ago
How did you create your table on your custom page?
astronomic
astronomicβ€’14mo ago
with html in views/filament/pages/custompage
Patrick Boivin
Patrick Boivinβ€’14mo 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
astronomicβ€’14mo ago
I'll look to see about it, sorry, I'm a newbie infilament
Patrick Boivin
Patrick Boivinβ€’14mo ago
No worries! I'm also a newbie πŸ˜„
astronomic
astronomicβ€’14mo 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β€’14mo ago
Can you rewrite it to use getTableQuery()?
astronomic
astronomicβ€’14mo 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β€’14mo ago
using a relationship column?
astronomic
astronomicβ€’14mo ago
And how would that be?
Dan Harrin
Dan Harrinβ€’14mo ago
search "column relationship data" in the docs
astronomic
astronomicβ€’14mo 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β€’14mo ago
you cant pass a query in the render method it has to be getTableQuery()
astronomic
astronomicβ€’14mo 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();