Ctreeview's Item customization

Hi,

Is there a way that we can add attributes to the generated li tags ? Both parent and children of course.

Regards,

xavier

What sort of attributes are you looking to add? The "id" attribute is available to be set on each <li> entity as in the following example data array:


$dataTree = array(

                   	array(

                           	'text'=>'Grampa', 

		   	'id'=>'grandpa-id'

                           	'children'=>array(                                    	

			array(

                                           	'text'=>'Father',

				'id'=>father-id',

                                           	'children'=>array(

                                                   	array('text'=>'me', 'id'=>'me-id'),

                                                   	array('text'=>'big sis', 'id'='sis-id'),

                                                   	array('text'=>'little brother', 'id'=>'bro-id'),

                                           	)

                                   	),

                                   	

                           	)

                   	)

           	);

which, when used with the CTreeView widget will render something like the following HTML:

[html]<ul id="yw0">

<li id="grandpa-id">Grampa

<ul>

<li id="father-id">Father

<ul>

<li id="me-id">me</li>

<li id="sis-id">big sis</li>

<li id="bro-id">little brother</li>

</ul>

</li>

</ul>

</li>

</ul>

[/html]

Hi Jefftulsa,

thanks for the reply. I would like to just add an attribute like


class="something"

.

xav

I’m afraid it’s not possible to add a custom class as per current implementation…

The rendering of the items is done by the method saveDataAsHtml() - http://www.yiiframew…taAsHtml-detail

To solve this you would need to extend the CTreeView and make a custom saveDataAsHtml() that would take into account a new data structure (with a custom class)…

Edit:

But again if you just need to add a class to every parent and every child so to make same CSS rules for them… you can do that without making all these changes…

Hi thanks for the answer.

It would have been convenient but as I’m using jquery for ajax updates of the tree I’ll try another strategy.

Again, many thanks.

Regards,

Xav