Giter Site home page Giter Site logo

More intelligent sorting about isotope HOT 22 CLOSED

desandro avatar desandro commented on July 4, 2024
More intelligent sorting

from isotope.

Comments (22)

desandro avatar desandro commented on July 4, 2024

See also #29

from isotope.

desandro avatar desandro commented on July 4, 2024

Just spitballin' here...

Picking up on @joshhepworth idea in #29. I'm thinking that this could be achieved by adding a new option, multiSort. It would accept an array. Each item in the array would be an object. Each item would have a sortBy property, and an optional sortAscending property. So it would look something like:

// sorts category, then price low-to-high, then most recent date
$('#container').isotope({
  multiSort: [
    { sortBy: 'category' },
    { sortBy: 'price' },
    { sortBy: 'date', sortAscending: false }
  ]
});

This way, we can preserve backwards compatibility, and rely sortBy and sortAscending properties like before.

Right now, _sort() is already hooked up to fallback to 'original-order' if the first comparison matches. So you can already see how one might add a loop in there that uses the next object if the previous comparison matches.

I think this is totally do-able. I might take a swing at it in the next couple weeks.

from isotope.

j-hernandez avatar j-hernandez commented on July 4, 2024

+1 for some multiSort. I've got some users that are absolute junkies when it comes to sorting and filtering. May have a go at it this weekend myself.

from isotope.

 avatar commented on July 4, 2024

+1 also

from isotope.

cjroebuck avatar cjroebuck commented on July 4, 2024

+1

from isotope.

mattsaddo avatar mattsaddo commented on July 4, 2024

+1

from isotope.

fk avatar fk commented on July 4, 2024

+1

from isotope.

JoelSutherland avatar JoelSutherland commented on July 4, 2024

I would rather see this implemented in a way that allowed more complete flexibility. The traditional solution to custom sorting would allow passing in a function that defined the sort:

$('#container').isotope({
    sortBy: function($a,$b){
        return $a.data('val') > $b.data('val');
    }
});

The obvious consequence is the loss of the ability to index on item insertion since this would occur at sort-time, but unless there are HUNDREDS of elements in your grid this shouldn't be an issue.

This solution would allow any arbitrary sort to take place. It would also be a great model for complex filters.

from isotope.

desandro avatar desandro commented on July 4, 2024

@JoelSutherland That is a terrific solution. Easily for me to implement, and, like you said, provides for lots of flexibility.

Marking this for v1.6

from isotope.

JoelSutherland avatar JoelSutherland commented on July 4, 2024

Wow! That's awesome!

Not to get greedy...but would this be possible for filtering too?

$('#container').isotope({
    filter: function($el){
        return $el.data('val') > 5;
    });

This would have the same benefit there and also potentially make the plugin easier to understand as a whole as both common methods would be similar.

from isotope.

hugomrdias avatar hugomrdias commented on July 4, 2024

check this for complex filtering

#144 (comment)

from isotope.

ultimatedelman avatar ultimatedelman commented on July 4, 2024

I know this is closed, but I don't see this on the documentation anywhere, and the referenced issue has been closed as well. Has this been implemented? If so, which version?

from isotope.

desandro avatar desandro commented on July 4, 2024

@ultimatedelman This issue is very much still open. No, this has not been implemented. Sorry, I'm not planning on resolving this in the near future. However, you are free to re-tool Isotope as you see fit to get it done.

from isotope.

ultimatedelman avatar ultimatedelman commented on July 4, 2024

@desandro would you be ok if i enabled the user to pass a comma-delimited string to indicate sort order? i know you're not down with "magic" args, but this is still a string, and if no commas are included, the original functionality would still work.

from isotope.

ultimatedelman avatar ultimatedelman commented on July 4, 2024

Ok, I rewrote the sorting algorithm a bit to incorporate a comma-delimited string and do a multi-sort based on that. This is just a proof of concept and hasn't really been tested with any of the other functionality isotope offers. I haven't really optimized it either, so I can't vouch for how efficient it is (maybe you can clean it up?) but I have done some of the heavy lifting for you. I'll clean this up a bit on my own and submit a pull request in a bit.

Hope this helps!

from isotope.

egbutter avatar egbutter commented on July 4, 2024

@ultimatedelman @desandro I am still getting a feel for isotope and infinity.js, but it (superficially) looks like there is some overlap with how @airbnb tracks element properties on continuous scroll views, using sorted arrays? They also mention that they are playing around with (balanced) binary trees: I believe those perform better in the worst cases than hash tables -- O(log(n)) vs. O(n).

from isotope.

farser avatar farser commented on July 4, 2024

thank you @ultimatedelman!

from isotope.

seiyria avatar seiyria commented on July 4, 2024

Has there been any progress on this idea? I know v2 is coming up and I was wondering if the situation had changed at all.

from isotope.

desandro avatar desandro commented on July 4, 2024

@seiyria yes! v2 docs have details about using functions for sorting and multiple sortBy.

from isotope.

seiyria avatar seiyria commented on July 4, 2024

@desandro Cool, thank you very much!

from isotope.

desandro avatar desandro commented on July 4, 2024

Isotope v2 is now released! See docs on filtering with function, and multiple sortBy

Merrily closing this old old issue. If you run into an issue with either of these features, please open a new issue.

from isotope.

thielpeter avatar thielpeter commented on July 4, 2024

Comes right in time thank you all very much :)

from isotope.

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.