brianreavis / sifter.js

A library for textually searching arrays and hashes of objects by property (or multiple properties). Designed specifically for autocomplete.
1.1k stars 125 forks source link

Multi-property sorting #2

Closed brianreavis closed 11 years ago

brianreavis commented 11 years ago

Add the ability to sort by multiple fields. The sort precedence will be based on the order of entries in the "sort" setting. Basic idea (the interface might vary):

sort: [
    {field: "$score", direction: "desc"},
    {field: "first_name", direction: "asc"},
    {field: "last_name", direction: "asc"},
]
score: 2, first_name: "shane", last_name: "mcconkey"
score: 2, first_name: "shane", last_name: "zebra"
score: 1, first_name: "aziz", last_name: "ansari"
score: 1, first_name: "nick", last_name: "offerman"
ghost commented 9 years ago

Hi Brian, Your tool is great and help me lot of time building custom select boxes. Thanks for the amazing widget.

I have one question on sorting multiple fields.

Below is the example code for your perusal.

Eg:

Initializing the sifter by multiple sort fields. $("#sample").selectize({ create:false, maxItems:1, sort: [ {field: "value", direction: "asc"}, {field: "text", direction: "asc"}
] });

Now if the user search, it should sort the searched text based on value ascending and text ascending order. But am able to get the desired result.

Can you see where the problem is?

Cheers mate..!

Fazeel