-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to order results #28
Comments
I have run into a similar issue and initially was just passing public function sortCol($col)
{
$this->orderBy($col, $this->input('sort_dir', 'DESC'));
} Then these methods started getting bloated when ordering by a relation that wasn't joined and having to add each relation's join query. That eventually turned into: public function sortCol($col)
{
if(method_exists($this, $method = 'orderBy'.studly_case($col))) {
return $this->$method();
}
$this->orderBy($col, $this->input('sort_dir', 'DESC'));
}
public function orderByClientNumber()
{
$this->join('clients', 'clients.user_id', '=', 'users.id')
->orderBy('clients.work_phone', $this->input('sort_dir', 'DESC'));
} I'm not sure I like that solution though... I'm totally open to suggestions on this one as it's been coming up a bit more frequently for me. |
@Tucker-Eric I like the method you've provided, I actually added an additional if statement around the pure
Only issue is that the table name needs to be included. Perhaps there is a cleaner way? |
I would define an orderable method on the filter to be able to tune it per model/filter/query and fallback to a default sort. Something like:
Then you can do:
That way you're not adding another query to check for the existence of a column and you are reverting back to your default when the column isn't recognized. |
Hi,
This is a great package and it is really helping my project.
One thing I miss is the ability to order results based on query parameters.
Any thoughts?
The text was updated successfully, but these errors were encountered: