Giter Site home page Giter Site logo

Sorting by aliases about column-sortable HOT 6 CLOSED

kyslik avatar kyslik commented on August 25, 2024
Sorting by aliases

from column-sortable.

Comments (6)

Kyslik avatar Kyslik commented on August 25, 2024

I will try to make it work. Thank you for suggestion with $sortable array.

Isn't it possible to use https://github.com/Kyslik/column-sortable#columnsortable-overloading-advanced ?

from column-sortable.

veganista avatar veganista commented on August 25, 2024

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.

from column-sortable.

Kyslik avatar Kyslik commented on August 25, 2024

I think something like introducing new variable would be nice, maybe:

$sortableAliases = []

Or something similar, I will think about it and make it work.


WIP, aliases expected in new minor version

from column-sortable.

Kyslik avatar Kyslik commented on August 25, 2024

@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...

SELECT neededfield, CONCAT(firstname, ' ', lastname) as full_name ...

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.

from column-sortable.

Kyslik avatar Kyslik commented on August 25, 2024

@veganista try on dev-master, see README.md and please report back if everything OK.

from column-sortable.

veganista avatar veganista commented on August 25, 2024

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

from column-sortable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.