Neel help to create Delete button

Sorry for typo. How to create button or link for delete/update on the top?

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

‘dataProvider’=>$dataProvider,

‘showTableOnEmpty’=>false,

‘selectableRows’=>2,

‘emptyText’=>‘Nowt to see.’,

‘columns’=>array(

array(

‘class’=>‘CCheckBoxColumn’,

‘name’=>‘delete’,

‘value’=>’$data->id’,

‘id’=>‘delete’

),

‘name’,

‘loginName’,

‘password’,

‘email’,

),

)); ?>

You could try something like this




<?php echo CHtml::beginForm(); ?>


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

	blahblahblah

)); ?>


<?php echo CHtml::ajaxSubmitButton('Delete Item(s)', CController::createUrl('example/DeleteAjax')); ?>


<?php echo CHtml::endForm(); ?>




And then in your controller just pop in an actionDeleteAjax function to handle the request.

Here is my view file

<?php echo CHtml::beginForm(); ?>

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'dataProvider'=&gt;&#036;dataProvider,


'showTableOnEmpty'=&gt;false,


'selectableRows'=&gt;2,


'emptyText'=&gt;'Now to see.',





'columns'=&gt;array(


	


	array(


	'class'=&gt;'CCheckBoxColumn',


	'name'=&gt;'delete',


	'value'=&gt;'&#036;data-&gt;id',


	'id'=&gt;'delete'


	),	


	'first',


	'last',


	'note',


array(


    'class'=&gt;'CButtonColumn1',


   //'viewButtonUrl'=&gt;'Yii::app()-&gt;createUrl(&quot;/user/show&quot;, array(&quot;id&quot; =&gt; &#036;data-&gt;id))',


   //'updateButtonUrl'=&gt;'Yii::app()-&gt;createUrl(&quot;/user/update&quot;, array(&quot;id&quot; =&gt; &#036;data-&gt;id))',


    


   ),		


),

));

?>

<?php echo CHtml::ajaxSubmitButton(‘Delete Item(s)’, CController::createUrl(’/delete’)); ?>

<?php echo CHtml::endForm(); ?>

Do you have actionDeleteAjax controller action? My action controller is not working.

Yes, if you used the Yiic shell to automatically generate your controller, the data the Delete action expects will be formatted differently, in this case $_POST[‘delete’][$i][$id] vs $_GET[‘id’], so you should either modify that action or just create a new one.

I tried but my controller is not working. Can you post an example?

Here is just a quickie way that should get you started at least




public function actionDeleteAjax()

{

    for ($i = 0; $i < sizeof($_POST['delete']); $i++)

    {

        if ($model = Example::model()->findbyPk($_POST['delete'][$i]))

            $model->delete();

    }

}



When I click submit button, not go to controller.

<?php echo CHtml::beginForm(); ?>

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

‘dataProvider’=>$dataProvider,

‘showTableOnEmpty’=>false,

‘selectableRows’=>2,

‘emptyText’=>‘Now to see.’,

‘columns’=>array(

array(

‘class’=>‘CCheckBoxColumn’,

‘name’=>‘delete’,

‘value’=>’$data->id’,

‘id’=>‘delete’

),

‘first’,

‘last’,

‘note’,

array(

‘class’=>‘CButtonColumn1’,

//‘viewButtonUrl’=>‘Yii::app()->createUrl("/user/show", array(“id” => $data->id))’,

//‘updateButtonUrl’=>‘Yii::app()->createUrl("/user/update", array(“id” => $data->id))’,

),

),

));

?>

<?php echo CHtml::ajaxSubmitButton(‘Delete Item(s)’, CController::createUrl(‘delete’)); ?>

<?php echo CHtml::endForm(); ?>

Why this button not working? Can anyone help me

<?php echo CHtml::ajaxSubmitButton(‘Delete Item(s)’, CController::createUrl(‘delete’)); ?>

full view file

<?php echo CHtml::beginForm(); ?>

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

‘dataProvider’=>$dataProvider,

‘showTableOnEmpty’=>false,

‘selectableRows’=>2,

‘emptyText’=>‘Now to see.’,

‘columns’=>array(

array(

‘class’=>‘CCheckBoxColumn’,

‘name’=>‘delete’,

‘value’=>’$data->id’,

‘id’=>‘delete’

),

‘first’,

‘last’,

‘note’,

array(

‘class’=>‘CButtonColumn1’,

//‘viewButtonUrl’=>‘Yii::app()->createUrl("/user/show", array(“id” => $data->id))’,

//‘updateButtonUrl’=>‘Yii::app()->createUrl("/user/update", array(“id” => $data->id))’,

),

),

));

?>

<?php echo CHtml::ajaxSubmitButton(‘Delete Item(s)’, CController::createUrl(‘delete’)); ?>

<?php echo CHtml::endForm(); ?>

Please help me. I need to delete data using CCheckBoxColumn. I really appreciate if anyone help me to solve this problem.

http://www.yiiframework.com/forum/index.php?/topic/7872-strange-ajaxsubmitbutton-problem-multiple-posts/page__gopid__111386#entry111386