Simple Ultimate Edition selected for jquery easyui treegrid Cascade

Source: Internet
Author: User
Tags types of extensions

Recently I need to do something about permissions. jquery easyui treegrid 1.2.6 is used in the background. Unfortunately, there is no Cascade check function.

Tree format

0

---- 1

-------- 2

-------- 3

---- 4

-------- 5

-------- 6

-------- 7

The root node is 0 and the level is 0. There are two subnodes, 1 and 1,

The subnode has multiple nodes, namely, 2, 3, 6, and 7, and the level is 2.

The requirements are as follows:

1. When selecting the root node 0, all descendant nodes must be selected, and all nodes from 1 to 7 must be selected.

2. When the root node 0 is deselected, all descendant nodes must be deselected. All nodes from 1 to 7 must be deselected.

3. When Node 1 is selected, the parent node 0 of Node 1 must also be selected. However, other child nodes of node 0 cannot be automatically selected and remain unchanged.

4. When the node 1 is canceled, the Child Nodes in step 2 and Step 2 are canceled.

5. When selecting 2 nodes, You need to select 1 and 0 nodes,

6. when canceling 2, check whether 3 is selected. If yes, select 1. If no 3 is selected, select 1. If 0 is selected, check whether 1 or 4 is selected.

To sum up

1. When selecting a node, You must select all the child nodes under the node.

2. When selecting a node, You must select the parent node of the node, including all the previous parent nodes.

When canceling a node, if none of its sibling nodes are selected, the parent node is also deselected,

In other words, you need to check whether the child nodes under the parent node have been selected. If one is selected, the parent node is also deselected.

------------- Finding the work done by the predecessors was successful

Search for an articleArticle, Thanks to the original author

Treegrid Cascade check Select Or deep cascade check Select Extensions: two types of extensions

There are two ways to achieve the above requirement: 1. Part of implementation 2,

However, when the node is canceled,Is the parent node canceled?

I mainly useMethod 2 (attribute mode, non-function mode)Here, I added a function to determine whether the parent node needs to be canceled.

 1   /*  *  2   * Cascade to determine whether a child node of the parent node has been selected  3  * @ Param {object} target  4   * @ Param {object} ID node ID  5   * @ Return {typename}  6    */    7   Function  Isparenthasselectedchildren (target, ID, idfield, status)  8   {  9       VaR Count = 0 ;  10      VaR Children = target. treegrid ('getchildren' , ID );  11       VaR Selectnodes = $ (target). treegrid ('getselections '); //  Obtain the selected item  12       VaR P = target. treegrid ('Find' , ID );  13       //  Note: The children here refers to all child nodes of the descendant, not the son node. Therefore, add children [I] ['_ parentid'] = P [idfield] to filter out the son node.  14      For ( VaR I = 0; I <children. length; I ++ )  15   {  16           VaR Childid = Children [I] [idfield];  17           For ( VaR J = 0; j <selectnodes. length; j ++ ){  18               If (Selectnodes [J] [idfield] = childid & Children [I] ['_ parentid'] = P [idfield])  19 Count ++ ;  20   }  21   }  22       //  Note: The click function runs before the unselect event. Here, you need to subtract yourself.  23       Return Count-1> 0 ;  24 }

Mainly Adding FunctionsIsparenthasselectedchildrenThe number of child nodes under the parent node is greater than 0 to determine whether to cancel the parent node

In this example, the last count is reduced by one, indicating that the current click event is related to the onselect event, indicating to exclude yourself,

In the FunctionSelectparentAdd the ninth lineCalled

 

 1   Function  Selectparent (target, ID, idfield, status ){  2       VaR Parent = target. treegrid ('getparent', ID );  3       If  (Parent ){  4           VaR Parentid = Parent [idfield];  5           If  (Status)  6 Target. treegrid ('select' , Parentid );  7           Else    8   { 9               If (! Isparenthasselectedchildren (target, parentid, idfield ))  10 Target. treegrid ('unselect' , Parentid );  11   }  12   Selectparent (target, parentid, idfield, status );  13   }  14 }

 

 

 

 

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.