midrissi
6/11/2013 - 2:58 PM

Invert the grid selection

Invert the grid selection

waf.widget.Grid.prototype.invertSelection = function(){
	var sel = this.getSelection();
	if(sel.isModeMultiple()){
		var 	rows = sel.getSelectedRows(),
			index = 0,
			res = [];
			
		rows.sort(function(a,b){
			return a - b;
		});
			
		for(var i = 0; i < rows.length; i++){
			var row = rows[i];
			
			while(row > index){
				res.push(index++);
			}
			index = row + 1;
		}
		while(this.source.length > index){
			res.push(index++);
		}
		
		sel.setSelectedRows(res);
		
		this.$domNode.find('.container').trigger('scroll');
	}
}