Problem with eajaxlinkcolumn extension

Hello. I’m trying to use the following extension eajaxlinkcolumn. The extension basically adds ajax to a link in a column.

I’m having a hard time getting it to work. I’m thinking of resorting to custom JQuery but would like to stay as close to Yii as possible. Here’s the code:

Extension





<?php


Yii::import('zii.widgets.grid.CLinkColumn');


/**

 * CLinkColumn represents a grid view column that renders a ajax hyperlink in each of its data cells.

 * It uses CHtml::ajaxLink to render the link.

 *

 * @see CHtml::ajaxLink()

 *

 * @author Luke Jurgs

 * @version 0.0.3-2012-01-30

 */

class EAjaxLinkColumn extends CLinkColumn {

	/**

	 * @var string the label to the hyperlinks in the data cells. Note that the label will not

	 * be HTML-encoded when rendering. This property is ignored if {@link labelExpression} is set.

	 * @see labelExpression

	 */

	public $label = 'AJAX Link';


	/**

	 * @var array the HTML options for the data cell tags.

	 */

	public $htmlOptions = array('class' => 'ajax-link-column');


	/**

	 * @var array the HTML options for the header cell tag.

	 */

	public $headerHtmlOptions = array('class' => 'ajax-link-column');


	/**

	 * @var array the HTML options for the footer cell tag.

	 */

	public $footerHtmlOptions = array('class' => 'ajax-link-column');


	/**

	 * @var array the AJAX options for the ajax link

	 * This property is merged with {@link linkAjaxOptionsExpression} if it is set.

	 * @see linkAjaxOptionsExpression

	 */

	public $linkAjaxOptions = array();


	/**

	 * @var array an array of PHPs expression that will be evaluated for every data cell and whose result will be rendered

	 * as the URL of the hyperlink of the data cells. In this expression, the variable

	 * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;

	 * and <code>$this</code> the column object. This array will be merged with linkAjaxOptions

	 * @see linkAjaxOptions

	 */

	public $linkAjaxOptionsExpression;


	/**

	 * @var array the HTML options for the ajax link

	 */

	public $linkHtmlOptions = array();


	//array_walk_recursive callback target, evaluates multidimensional arrays

	private function evaluateAjaxOption(&$value, $key, $data) {

		$value = $this->evaluateExpression($value, array('data' => $data['data'], 'row' => $data['row']));

	}


	/**

	 * Renders the data cell content.

	 * This method renders a hyperlink in the data cell.

	 * @param integer $row the row number (zero-based)

	 * @param mixed $data the data associated with the row

	 */

	protected function renderDataCellContent($row, $data) {

		if ($this->urlExpression !== null) {

			

			$url = $this->evaluateExpression($this->urlExpression, array('data' => $data, 'row' => $row));

		} else {

			$url = $this->url;

		}

		if ($this->labelExpression !== null) {

			$label = $this->evaluateExpression($this->labelExpression, array('data' => $data, 'row' => $row));

		} else {

			$label = $this->label;

		}


		$ajaxOptions = $this->linkAjaxOptions;

		if (($this->linkAjaxOptionsExpression !== null) && (is_array($this->linkAjaxOptionsExpression))) {

			$ajaxOptionsExpression = $this->linkAjaxOptionsExpression;

			array_walk_recursive($ajaxOptionsExpression, array($this, 'evaluateAjaxOption'), array('data' => $data, 'row' => $row));

			$ajaxOptions = CMap::mergeArray($ajaxOptions, $ajaxOptionsExpression);

		}


		$label = (is_string($this->imageUrl) ? CHtml::image($this->imageUrl, $label) : $label);


		echo CHtml::ajaxLink($label,$url, $ajaxOptions, $this->linkHtmlOptions);

	}

}







$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'timeentries-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'project',

		'projectitem',

		'date',

		'notes',

		array(

		'class'=>'ext.EAjaxLinkColumn',

		'header'=>'Time',	

		'labelExpression'=>'$data->time',

		'url' => Yii::app()->createUrl('timeentries/test'),

		'linkAjaxOptions' => array(

         'type' => 'POST',

         'dataType' => 'json',

      		),

		'linkAjaxOptionsExpression' => array(

         'data' => array(

         'id' => '$data->internalid' //note that $data->id is an expression so must be quoted

         ),

         ),

         ),

		array(

			'class'=>'CButtonColumn',

		),

	),

));




	

        public function actionTest()

	{	

		echo 'testing';

	}



I have two issues:

  1. The url is not converting to my controller/action. Its really strange because when I evaluate the $url in either the extension or the view, it displays the right $url but for some reason when I use CHtml::ajaxLink($label,$url, $ajaxOptions, $this->linkHtmlOptions); the url displays as the current page. Reading the class reference it says this can happen if the url is null but I’ve confirmed that its not null and it points the url to my desired controller/action.

  2. Once the database is updated I’d like to update the value of my linked cell with the calculated result. I think I need to use array(‘update’ => ‘#id’) in the ajax options, but how do I control for dynamic ids being added to the view?