Reputation: 55
Does anyone knows how to put checkbox in CTree
?? I already have my treeview
but I don't know how to put checkbox on it and return 0 || 1
result.. please help.. Thanks..
array("id"=>1,"name"=>"<b>SALES</b>","parents"=>
array(
array("id"=>10,"name"=>"<b>Sales Order</b>","parents"=>
array(
array("id"=>100,"name"=>"Allow view Transaction PO",
array('text' => CHtml::checkBox('name', true)),"parents"
),
array("id"=>101,"name"=>"Allow Click Edit Button PO","parents"
),
array("id"=>101,"name"=>"Allow Click New Button PO","parents"
),
array("id"=>101,"name"=>"Allow Click Save Button PO","parents"
),
array("id"=>101,"name"=>"Allow Click Change Document# PO","parents"
),
array("id"=>101,"name"=>"Allow Click Delete Button PO","parents"
),
array("id"=>101,"name"=>"Allow Click Print Button PO","parents"
),
array("id"=>101,"name"=>"Allow Click Lock Button PO","parents"
),
array("id"=>101,"name"=>"Allow Click Unlock Button PO","parents"
),
array("id"=>101,"name"=>"Un Allow Change Amount PO","parents"
),
),
),
),
)
Upvotes: 4
Views: 1268
Reputation: 518
Try use dynatree
Create new function for tree: mytree()
$(function () {
$("#tree2").dynatree({
checkbox: true,
selectMode: 2,
children: <?php echo json_encode(Department::model()->mytree(75))?>,
onSelect: function (select, node) {
// Display list of selected nodes
var selNodes = node.tree.getSelectedNodes();
// convert to title/key array
var selKeys = $.map(selNodes, function (node) {
return node.data.ID;
});
$("#echoSelection2").text(selKeys.join(", "));
// $("#departments").val(selKeys.join(", "));
},
onClick: function (node, event) {
// We should not toggle, if target was "checkbox", because this
// would result in double-toggle (i.e. no toggle)
if (node.getEventTargetType(event) == "title")
node.toggleSelect();
},
onKeydown: function (node, event) {
if (event.which == 32) {
node.toggleSelect();
return false;
}
},
}
}
Html code
<div id="tree2" style="max-height: 250px;max-width:300px;overflow:scroll; " class="noshowchecktree controls "></div>
Result:
Upvotes: 3
Reputation: 2928
Try a checkbox in the text property for each element:
array(
...,
'text' => CHtml::checkBox('name', true|false) ....
)
Upvotes: 3