Hi Tommy,
Sorry I am too new to ajax and yii to understand snippets
I am hoping for actual examples. Anyway I now following toMeloos guide over here but still can’t get the button to work.
Instead of the extended ButtonColumnEx, I am following his examples by using the default CButtonColumn.
I am posting the same reply here now. Can you help to get it work?
Got this error, after clicking on the "up/down" buttons on the grid
Error 400
Invalid request. Please do not repeat this request again.
admin.php
<?php
$this->renderPartial('_admin',array('dataProvider'=>$dataProvider,));
?>
_admin.php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'profileGrid',
'dataProvider'=>$dataProvider,
'columns'=>array(
'Id',
'Title',
array(
'class'=>'CButtonColumn',
'buttons'=>array(
'up'=>array(
'label'=>'up',
'imageUrl'=>Yii::app()->request->baseUrl . '/images/uparrow.png',
'url'=>'Yii::app()->createUrl("/item/reposition")',
'ajax'=>'
array(
"url"=>Yii::app()->createUrl("/item/reposition"),
"data"=>array("id"=>$data->id,"direction"=>"up",),
"update"=>"#profileGrid"
)',
),
'down'=>array(
'label'=>'down',
'imageUrl'=>Yii::app()->request->baseUrl . '/images/downarrow.png',
'url'=>'Yii::app()->createUrl("/item/reposition")',
'ajax'=>'
array(
"url"=>Yii::app()->createUrl("/item/reposition"),
"data"=>array("id"=>$data->id,"direction"=>"down",),
"update"=>"#profileGrid"
)',
),
),
'template'=> '{up} {down}',
),
),
itemController.php
public function actionReposition()
{
if(Yii::app()->request->isAjaxRequest)
{
if(isset($_GET['direction']) &&
isset($_GET['id']) )
{
$direction=$_GET['direction'];
$id=$_GET['id'];
if ($direction=='up') {
$newSortOrder = $sortOrder-1;
} else if ($direction=='down') {
$newSortOrder = $sortOrder+1;
}
//** do my db stuff here **//
$dataProvider=new CActiveDataProvider('Product', array(
'criteria'=>array(
'order'=>'SortOrder ASC',
),
)
);
$this->renderPartial('_admin',array('dataProvider'=>$dataProvider,));
}
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
It looks like it is not detecting Yii::app()->request->isAjaxRequest. if remark this line,it does not detect $_GET[‘direction’] or $_GET[‘id’]