user1383163
user1383163

Reputation: 597

dojo 1.10 adding sort behaviour of CheckedMultiSelect

Hello everyone i am desperately trying to sort a CheckedMultiSelect with little luck, it seems that despite changing the order of the data in the store it is always displayed alphabetically.

Being relatively new to dojo i have tried to look around for a tutorial but alas i am having no joy.

Can someone explain to me how best to sort the data in a CheckedMultiSelect that is being populated by a Memory store?

Code:

var store = new Memory({'data', : data});
//where this is my CheckedMultiSelect box
this._set("store", store);

in my postCreate function i now do this:

this.options = this.store.query({}, {sort: [{attribute: "name", descending: "true"}]});
this._set("labelAttr", "name");
 console.log(this.options);

I can see both in firebug and in console that the data is in the right order however now i cannot see anything but checkboxes, there is a space where the value of that selection should be).

I dont know if this is going to help at all but this is the code that sets the data that populates the multi select, everything beforehand is just parsing of a string into the store object.

No matter what I do i cannot get the order to change, even changing the order of the elements in the stores data does not make a blind bit of difference, i am guessing there is some sort of behaviour that CheckedMultiSelect has in regards to sorting but it is just that; a guess.

Upvotes: 2

Views: 329

Answers (1)

inanutshellus
inanutshellus

Reputation: 10001

You set sortByLabel: false, then provide a queryOptions object (see example below).

As to why we'd need sortByLabel, see _FormSelectWidget:

    // sortByLabel: Boolean
    //      Flag to sort the options returned from a store by the label of
    //      the store.
    sortByLabel: true,

... Though there appear to be plans to deprecate it.

Here's the example:

var checkedMultiSelect = new CheckedMultiSelect ({
    dropDown: true,
    multiple: true,
    labelAttr: "label", // Need this to be able to use Memory directly
    sortByLabel: false, // Need this to override sort
    queryOptions: {     // Now, finally, specify sort order.
        sort: [
          {attribute:'sortByMeFirst'},
          {attribute:'sortByMeSecond', descending: true}
        ]
    },
    store: memoryStore
}, "dropdown");

See: jsfiddle sorting a CheckedMultiSelect

Upvotes: 3

Related Questions