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