Reputation: 164
I have a two MultiSelect lists, can the left list be sorted after I move any value from right list to left?
button= new Button({
label: "move left",
onClick: lang.hitch(this, function(){
dijit.byId(leftListId).addSelected(dijit.byId(rightListId));
})
Upvotes: 1
Views: 931
Reputation: 44725
You can't, at least not directly. The MultiSelect
is one of the simplest widgets I think and is just a wrapper.
This means that there are no special features included and if you want to have a sort functionality you will have to make one by yourself.
The best way of making one by yourself is by extending the widget. An example:
declare("dijit/form/MultiSelect", [MultiSelect], {
sort: function() {
var domNodes = Array.prototype.slice.call(this.containerNode.children);
domNodes.sort(function(a, b) {
if (a.innerHTML < b.innerHTML) {
return -1;
} else if (a.innerHTML == b.innerHTML) {
return 0;
} else {
return 1;
}
});
this.containerNode.innerHTML = "";
array.forEach(domNodes, function(node) {
this.containerNode.appendChild(node);
}, this);
}
});
What this does is pretty easy. We add a function called sort()
and then we just retrieve a list of all children, sort these children with the sort()
function of an array and then we remove all children and add the sorted children.
To use it you can now do something like: dijit.byId(leftListId).sort()
right after you executed your addSelected()
.
An example JSFiddle can be found here.
Upvotes: 3