Expansion state of CTreeView does not get saved to cookie

Hello toghether,

I have a problem with saving the expansion state of a CTreeView: I set the ‘persistent’ attribute to ‘cookie’ and also passed a cookieId to the widget. However, the state of the tree is not saved and restored.

The cookie itself is created, but is always empty. I also debugged a bit into jquery.treeview.js (not allowed to link it here :( ) and found out that upon page loading in line 193 the variable ‘branches’ is filled. But when I later click on the tree (= expand a node) and as a result the serialize() function gets triggered, ‘branches’ is empty again and therefore nothing is written into the cookie.

I would be grateful for every slight guess/idea/hint/… since this issue has already cost me quite some time (and all the patient guys in the IRC channel as well ;) ).

Cheers

spacegaier

I figured posting some code might actually help in this topic, so here we go:


$this->widget(

        	'CTreeView',

        	array(

            	'id'=>'group-tree',

            	'url' => CHtml::normalizeUrl(array('ajaxFillGroupTree', 'tid'=>$this->tournament->tid)),

            	'persist' => 'cookie',

            	'cookieId' => 'group-tree',

            	'animated' => 'fast'

            	//'collapsed' => true

            	)

);

The tree gets populated via AJAX without any problems.

That is the code that fills the tree (later there should only be one child level below the root node, but for testing I added a second one):


public function actionAjaxFillGroupTree($tid)

	{

    	if(!Yii::app()->request->isAjaxRequest) 

        	exit();

    	

    	$parentId = "NULL";

    	

    	$data = array();

    	$children = array();            	

            	

    	if(isset($_GET['root']) && $_GET['root'] !== 'source')

        	$parentId = (int)$_GET['root'];

   		

    	if($parentId == 'NULL')

    	{                	

        	$criteria=new CDbCriteria;

        	$criteria->select='id, name, dates_locked';

        	$criteria->condition='tid=:tid';

        	$criteria->params=array(':tid'=>$tid);

        	$criteria->order='name ASC';

        	$groups=Groups::model()->findAll($criteria);

        	

        	$test = array();

        	array_push($test, array('id'=>9999, 'text'=>"TESTESTSET", 'hasChildren'=>false));

        	

        	

        	foreach($groups as $group)

        	{

            	if($group->dates_locked)

                	$img = 'images/icons/lock.png';

            	else

                	$img = 'images/icons/lock_open.png';

            	

            	$text = '<img height=16 style="margin-right: 3px;" src="' . $img . '" /><a class="sidebarTreeLink" href="#" url="' . CHtml::normalizeUrl(array('tournament/viewgroup', 'tid'=>$tid, 'id'=>$group->id)) .'">' . $group->name . '</a>';

            	array_push($children, array('id'=>$group->id, 'text'=>$text, 'children'=>$test));

        	}

        	

        	array_push($data, array('text'=>'<b style="font-size: 120%;">Groups</b>', 'id'=>0, 'children'=>$children));

    	}                               		

       		

    	echo CTreeView::saveDataAsJson($data);

    	exit();

	}

As I said before: Grateful for anything ranging from slight guesses to full blown examples ;) !

No ideas, what might be the reason for the empty cookies?

Seems that ‘persist’ is not working with async treeview…

CTreeView is based on this plugin - http://bassistance.de/jquery-plugins/jquery-plugin-treeview/

In the downloaded file there is a todo file… where is written that this has still to be done…

Okay, but since it seems as if development of http://bassistance.d…lugin-treeview/ is on hold, I assume that this won’t be fixed in the near future :( .

The author announced in the April that this is discontinued, but then in October released a new version… so you never now… :D

as the jQuery UI version is still not out… maybe he will work on his solution… you can try to open a new issue/request on the github project…