This extension provides a tree view in a CGridView.
I made it because i tried to use several from Yii extension for this purpose and none of them worked for me. Probably there are a few bugs.
Requirements
Yii 1.1 or above
Usage
Download extension from downloads and upload into the extensions folder
$this->widget('ext.SilcomTreeGridView.SilcomTreeGridView', array(
'id'=>'your-grid-id',
'treeViewOptions'=>array(
'initialState'=>'collapsed',
'expandable'=>true,
),
'parentColumn'=>'parent_id',
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
'name',
)
));
Resources
Using http://ludo.cubicphuse.nl/jquery-treetable/
Change Log September 29, 2014
Minor correction in function that order the nodes
September 02, 2014
Initial release.
Very handy - just what I needed.
Thanks for this - I like what you've done. It works almost flawessly.
One minor issue is that the following line:
if ($insertedNode->getPrimaryKey() == $node->{$this->parentColumn}) {
should read:
if ($insertedNode->getPrimaryKey() == $node->{$this->parentColumn} && in_array($insertedNode, $oldOrderedData)) {
To ensure newly added nodes do not have their children inserted until the next loop, otherwise the ordering of nodes can get out of order.
@tomh
Thanks for the suggestion, it was added a new file with it
Thanks
It work well.thanks.
some tips:
1.you should add
$dataProvider=new CActiveDataProvider('XXX');
and so on in your controller.
2.if your root parent_id is 0,change line57:
if ($node->{$this->parentColumn} == null)
to:
if ($node->{$this->parentColumn} == 0)
3.if you want add filter,can do like this ext:http://www.yiiframework.com/extension/mctreegridview/.and change this code in lin 62:
if (count($orderedData) == 0){throw new Exception("Error, no roots found");}
should not throw error :
if (count($orderedData) == 0){return $orderedData;}
filter not work very well,if keep the parent followed by children,It can only filter some specially column,could't search children and if parent and children has different status,filter failed ,.if anyone can solve it,please tell me ,or the author @Bianchi add filter function?
4.if you want this look like CGriview css.you can change lin 186:
$row .= ' ' . $this->parentClass . $this->rowCssClass[$rowIndex % $n];
to this:
$row .= ' ' . $this->rowCssClass[$rowIndex % $n];
or define css yourself.
above this,I'm new about this,so I'm not sure it correct ,if there is mistake please point out.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.