PDA

View Full Version : How to remove thumb from multislider?



cankut
3 Jul 2013, 5:43 AM
Hi,

There exists "addThumb" method but no "removeThumb" for multislider.

What's the trick for removing certain thumb from multislider ?

slemmon
4 Jul 2013, 2:26 PM
I'm afraid there is not currently a method to remove an existing thumb.

Delajor
18 Mar 2014, 1:00 PM
This would be a very much appreciated feature.

slemmon
19 Mar 2014, 3:26 PM
There is a feature request opened for this internally: EXTJSIV-10563

Delajor
19 Mar 2014, 3:38 PM
Great! I hacked it in myself:
I had to find where the thumbs dom sat in the dom hierarchy, then remove it manually. Its not pretty since I'm using private members, but it works for anybody who needs similar functionality.

This function sits inside of a container class:

removeThumb : function(index){
var innerEl = this.multiSlider.thumbs[index].ownerCt.innerEl.dom;
innerEl.removeChild(this.multiSlider.thumbs[index].el.dom);
this.multiSlider.thumbs.splice(index,1);
for(var i = 0; i < this.multiSlider.thumbs.length; i++){

this.multiSlider.thumbs[i].index = i;

}
},

This did the trick.

I also noticed that if a thumb is added its automatically appended to the end of the thumb array, however, its value might not be greater then the previous thumb. If thumbs are out of order in this way, ie, indices and values not necessarily in order, then they don't work properly. In order to fix this, I had to re-sort the thumb array by value then reassign new valid indices to each thumb. This feels like buggy behavior to me. Again, here is my fix for anybody interested:

this.multiSlider.thumbs.sort(function(a,b){
return (a.value-b.value);
});

for(var i = 0; i < this.multiSlider.thumbs.length; i++){
this.multiSlider.thumbs[i].index = i;
}