Skip to content

Commit 3680937

Browse files
committed
Allow "sortField" to be a string (shorthand).
1 parent 1c7cc13 commit 3680937

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

docs/usage.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,18 @@ $(function() {
154154
</tr>
155155
<tr>
156156
<td valign="top"><code>sortField</code></td>
157-
<td valign="top">The name of the property to sort by. This is only used when the score of two or more items is identical.</td>
158-
<td valign="top"><code>string</code></td>
159-
<td valign="top"><code>null</code></td>
160-
</tr>
161-
<tr>
162-
<td valign="top"><code>sortDirection</code></td>
163-
<td valign="top">Sort direction ("asc" or "desc").</td>
164-
<td valign="top"><code>string</code></td>
165-
<td valign="top"><code>'asc'</code></td>
157+
<td valign="top">
158+
A single field or an array of fields to sort by. Each item in the array should be an object containing at
159+
least a "field" property. Optionally, "direction" can be set to "asc" or "desc". The
160+
order of the array defines the sort precedence.<br><br>
161+
162+
Unless present, a special "$score" field will be automatically added to the beginning
163+
of the sort list. This will make results sorted primarily by match quality (descending).<br><br>
164+
165+
For more information, see the <a href="https://github.com/brianreavis/sifter.js#sifterjs">sifter documentation</a>.
166+
</td>
167+
<td valign="top"><code>string|array</code></td>
168+
<td valign="top"><code>'$order'</code></td>
166169
</tr>
167170
<tr>
168171
<td valign="top"><code>searchField</td>

src/defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ Selectize.defaults = {
1818

1919
dataAttr: 'data-data',
2020
optgroupField: 'optgroup',
21-
sortField: {field: '$order'},
22-
sortDirection: 'asc',
2321
valueField: 'value',
2422
labelField: 'text',
2523
optgroupLabelField: 'label',
2624
optgroupValueField: 'value',
2725
optgroupOrder: null,
26+
27+
sortField: '$order',
2828
searchField: ['text'],
2929
searchConjunction: 'and',
3030

src/selectize.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,11 +829,15 @@ $.extend(Selectize.prototype, {
829829
*/
830830
getSearchOptions: function() {
831831
var settings = this.settings;
832+
var sort = settings.sortField;
833+
if (typeof sort === 'string') {
834+
sort = {field: sort};
835+
}
832836

833837
return {
834838
fields : settings.searchField,
835839
conjunction : settings.searchConjunction,
836-
sort : settings.sortField
840+
sort : sort
837841
};
838842
},
839843

0 commit comments

Comments
 (0)