Skip to content

Is there a way to toggle sort? #548

Answered by dominikb
akulmehta asked this question in Q&A
Discussion options

You must be logged in to vote

For information on how to sort see the docs: QueryBuilder Sorting

For sort-dependent rendering, you can fall back to using the underlying QueryBuilderRequest:

app(QueryBuilderRequest::class)->sorts()->contains('id'); // ascending
app(QueryBuilderRequest::class)->sorts()->contains('-id'); // descending
app(QueryBuilderRequest::class)->sorts()->contains(function($value, $key) {
    return in_array($value, ['-id', 'id']);
}); // no query defined sort for id was applied

You can query for the sort order directly in your blade template or save it in the context and pass it to the blade template.
From there you could use an if-else construct to dynamically apply classes or render icons.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@akulmehta
Comment options

Answer selected by akulmehta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants