CGridView column type that that renders a CHtml::ajaxLink(), it is able to evaluate the ajax options as PHP much the same way the CLinkColumn can evaluate a url or label.
It extends CLinkColumn, so anything it does, this can do.
Requirements ¶
Yii 1.1
Usage ¶
Uses the same syntax as CLinkColumn except you need to include the AJAX options:
Where the EAjaxLinkColumn.php file is located in the extensions directory.
//this is not a full CGridView declaration
$this->widget('zii.widgets.grid.CGridView', array(
'columns' => array(
array('class' => 'ext.EAjaxLinkColumn',
'label' => 'Link Text',
'url' => Yii::app()->createUrl('blah/blah'),
//linkAjaxOptions and linkAjaxOptionsExpression are merged together, so only put the ones
//that actually need to be evaluated in the latter
'linkAjaxOptions' => array(
'type' => 'POST',
'dataType' => 'json',
),
//In this expression, the variable $row the row number (zero-based);
//$data the data model for the row; and $this the column object.
'linkAjaxOptionsExpression' => array(
'data' => array(
'id' => '$data->id', //note that $data->id is an expression so must be quoted
//with php 5.3 or higher you can use an anonymous closure
'name' => function($data){
return $data->firstName . $data->lastName;
},
),
),
),
);
success message
thanks for such a valuable extension, it saved my too much time, but can you guided me how to show message like on success , etc.?
AJAX options
@sefburhan
You could use the linkAjaxOptions or linkAjaxOptionsExpression property and set the success property. For example:
'linkAjaxOptions' => array( 'type' => 'POST', 'dataType' => 'json', 'success' => "js: function() { alert('success!'); }", ),
Happy coding!
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.