PDA

View Full Version : TreePanel setChecked function



hAmpzter
2 Sep 2008, 4:40 AM
Hey!

I needed an setChecked-function to the TreePanel, so I made an Ext.override on that! So here is the code if someone is interrested! :)

Requirements:
Ext Js v2.2 (only tested version)



/**
* Ext.tree.TreePanel.setChecked
*
* @class Ext.tree.TreePanel
* @function setComponent()
* @author Jonas Skoogh
*/
Ext.override(Ext.tree.TreePanel, {
/**
* Checks all found TreeNode items
* @param {Mixed} list List of attribute values of items to check
* @param {String} a (optional) The attribute to search for (defaults to id)
* @param {Ext.tree.TreeNode} startNode (optional) The node to start from, defaults to the root
* @return {Array} An array of the checked TreeNodes
*/
setChecked : function(list, a, startNode){
startNode = startNode || this.root;
var r = [];
if(!Ext.isArray(list))
list = new array(list);

var f = function(){
if((!a && list.indexOf(this.id+'') >= 0) || (a && list.indexOf(this.attributes[a]+'') >= 0)){
this.getUI().toggleCheck(true);
r.push(this);
}
}
startNode.cascade(f);
return r;
}
});
Happy coding!
</Jonas>

Found this also: http://extjs.com/forum/showthread.php?p=195697

Latest changes:
2008-09-05: Some code-changes to make the code faster
2008-09-03: Bug with IE and single value