CHECKBOX in CTreeView

Does anyone know how to check the box in CTree ? I already have my treeview , but I don’t know how to check the box on it and return 0 || 1 return 0 || 1 result .. Please help .. Thank you ..

 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" ), ), ), ), ) 
+4
source share
2 answers

Try checking the text property for each element:

 array( ..., 'text' => CHtml::checkBox('name', true|false) .... ) 
+3
source

Try using dynatree
Create a new function for the 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 (ie 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:
enter image description here

+3
source

Source: https://habr.com/ru/post/1491554/


All Articles