Table: sortable() with counts() - Set initial orderBy "desc" possible?
In my table, i have a sortable "comment count" field.
If i click it, its initially ordered by "ASC" (e.g. from 0 comments -> Most comments), which is not what I want.
On initial click, I want see the posts with the most comments. (e.g. from Most comments -> 0 comments)
I need something like:
->sortable(initialOrderBy: 'desc')
(demo pseudo code)
Is this possible already and i missed the option?
4 Replies
maybe
$table->defaultSort('comments_count', 'desc')
My posts table is initially orderdBy title. This works fine using
$table->defaultSort('title')
.
The problem is the default orderBy for the sortable field "comment_count". It's default set to "asc"
(e.g. from 0 comments -> Most comments). I can't figure out, how to set it to "desc"
as inital order direction. (e.g. from Most comments -> 0 comments)
Because of this, I have to click the sort button two times in order to sort it into the preferred direction. ("desc"
, e.g. from Most comments -> 0 comments)
?
Your
modifyQueryUsing()
orders the table initally, but this is not what i need.
1. Initially the table is only ordered by title. (This works)
2. Than, the user clicks on sort "comment count". Now the count should be sorted "desc"
on first click.
I'm searching for a solution for 2. (Setting the initial sort direction to for a sortable field) At the moment, the first "sort" click has always orderBy "asc"
by default.
I my example, the generated SQL is the following on first click (order by "comments_count" asc). This is the current default behavior of sortable fields.
... but i want this (order by "comments_count" desc) on first click: