-
Notifications
You must be signed in to change notification settings - Fork 108
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
Sorting by aliases #44
Comments
I will try to make it work. Thank you for suggestion with Isn't it possible to use https://github.com/Kyslik/column-sortable#columnsortable-overloading-advanced ? |
Yes, overloading for the total field works for my example above. public function totalSortable($query, $direction)
{
return $query->orderBy('total', $direction);
} I think that this is probably the best solution rather than allowing the configuration of fields to be set. public $sortable = [
'total' => 'total',
'balance' => 'balance',
'anotherAliasedField' => 'anotherAliasedField',
'created_at',
]; Doesn't look great as it's not obvious why you would be repeating the field name and i can't think of another use case for allowing that. This is related to #24 as it would solve that guy's problem. |
I think something like introducing new variable would be nice, maybe:
Or something similar, I will think about it and make it work. WIP, aliases expected in new minor version |
@veganista Hey, I was thinking about fixing this issue. Anyway, #24 won't be fixed by this because OP uses accessor (manipulation with data after it is fetched) so there is no (virtual) column that package can sort by; in example below I show query with full_name and package could sort by it...
For that purpose there is that overloading functionality (which I use a lot in my projects), custom joins, custom selects etc. I will try fix this soon. |
@veganista try on |
Sorry for the delay in getting back on this, took me a while to get back on the project. Works as expected and much more concise than overloading. Thanks |
Anyway of doing something like this?
It currently produces the following error:
It's caused by the table name being added to the column here. I've tested by commenting out this line and it works but that's not the solution as it's the fix for #39.
Could it be possible to override this feature by specifying a field name when needed in the
Model::$sortable
config array?The text was updated successfully, but these errors were encountered: