EasyUI Forum
December 01, 2025, 12:50:29 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: custom 3 state tree check boxes  (Read 8793 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: January 30, 2015, 01:07:33 AM »

I am using a tree to control user access to the screens, the tree is attached to a user, and the user gets access to the tree items that are checked.

It works very well, but now I need to use the same tree to specify whether the access is read-only or full write access.

So my idea is to somehow change the tree-check icons for ones that represent read-only, read-write and no access (un-checked).

So each time you click the checkbox it would cycle through [ read-only, read-write, no-access ]

Is this possible to achieve relatively easy and will I be able to differentiate between the different check-type in the data ?

Logged

-- Licensed User --
jarry
Administrator
Hero Member
*****
Posts: 2302


View Profile Email
« Reply #1 on: January 30, 2015, 06:14:21 AM »

Please refer to the code below:
Code:
$('#tt').tree({
checkbox: false,
formatter:function(node){
var s = '<span style="display:inline-block;width:16px;height:16px" class="tree-flag tree-checkbox'+(node.flag||0)+'">&nbsp;</span>';
return s + node.text;
}
}).bind('click', function(e){
var flag = $(e.target).closest('span.tree-flag');
if (flag.length){
var t = flag.closest('div.tree-node');
var f = 0;
if (flag.hasClass('tree-checkbox0')){
f = 1;
} else if (flag.hasClass('tree-checkbox1')){
f = 2;
} else {
f = 0;
}
$('#tt').tree('update',{
target: t[0],
flag: f
})
}
})

Use a 'flag' property to represent the current node state(read-only,read-write,no access). Use the 'formatter' function to display the node's checkbox regarding its flag. Click a un-checked node, the node will be checked. Click it again, it will be indeterminate. etc.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!