Magicsuggest / magicsuggest

Multiple Selection Combo Box using Bootstrap 3
nicolasbize.com/magicsuggest/
1.3k stars 269 forks source link

groupBy order unpredictable #335

Open uotw opened 6 years ago

uotw commented 6 years ago

When magic suggest is initializes with groupBy:true it seems to place the groups in an unpredictable order. There's no preference for sorting the groups. I suggest adding a groupByOrder config option that takes the following options 'asc', 'desc', '[array of groups]'. The user can set their preferred order using an array of groups.

The relevant code is here: magicsuggest.js line 677

for(var grpName in _groups) {
    nbGroups += 1;
    $('<div/>', {
        'class': 'ms-res-group',
        html: grpName
    }).appendTo(ms.combobox);
    self._renderComboItems(_groups[grpName].items, true);
}

_groups will need to be cast as an array, though. Currently it's an object, resulting in the unpredictable order of groups. See more here re: this randomness here: https://stackoverflow.com/a/2647228/3198281