Extjs discussion on Selecting All treePanel + chekBox and clearing selected items

Source: Internet
Author: User

Copy codeThe Code is as follows:
// Tree
Var treePanel = new Ext. tree. TreePanel ({
Id: 'ptree ',
Region: 'west ',
Layout: 'anchor ',
Border: false,
RootVisible: false,
Root :{},
Listeners :{
Render: function (){
AuthorityTree (treePanel);/* render tree */
},
Checkchange: function (node, state ){
If (node. parentNode! = Null ){
// Select a subnode to select the corresponding parent node
Var pNode = node. parentNode;
If (state | treePanel. getChecked (id, pNode) = ""){
PNode. ui. toggleCheck (state); // trigger the parent node to be selected
PNode. attributes. checked = state;
}
}
TreeId = node. attributes. id;
TreeName = node. attributes. text;
}
}
});
// OPERATION button
Tbar :[{
Id: 'btnqingkong ',
Text: 'clear ',
IconCls: 'winupdate-icon ',
Handler: function (){
Var nodes = Ext. getCmp ('ptree '). getChecked ();
If (nodes & nodes. length ){
For (var I = 0; I <nodes. length; I ++ ){
// Set the UI status to unselected
Nodes [I]. getUI (). toggleCheck (false );
// Set the node attribute to the unselected status
Nodes [I]. attributes. checked = false;
}
}
}
},{
Id: 'btnquanxuany ',
Text: 'select all ',
IconCls: 'winupdate-icon ',
Handler: function (){
Var nodeT = Ext. getCmp ('ptree '). getRootNode ();
TreeCheckTrue (nodeT );
}
}]
/**
* Select all checkTree
*/
Var treeCheckTrue = function (node)
{
Node. eachChild (function (child ){
Child. getUI (). toggleCheck (true );
Child. attributes. checked = true;
TreeCheckTrue (child );
});
}
/**
* CheckTree clearing
*/
Var treeCheckfalse = function (tree)
{
Var nodes = tree. getChecked ();
If (nodes & nodes. length ){
For (var I = 0; I <nodes. length; I ++ ){
// Set the UI status to unselected
Nodes [I]. getUI (). toggleCheck (false );
// Set the node attribute to the unselected status
Nodes [I]. attributes. checked = false;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.