Delete All Button

I wanna delete checked records when i am click the delete button

i am try with below code but not success pls give the solution

i am new to the yii

below is my view file

<?php

/* @var $this UsersController */

/* @var $model Users */

$this->breadcrumbs=array(

'Users'=&gt;array('index'),


'Manage',

);

$this->menu=array(

array('label'=&gt;'List Users', 'url'=&gt;array('index')),


array('label'=&gt;'Create Users', 'url'=&gt;array('create')),

);

Yii::app()->clientScript->registerScript(‘search’, "

$(’.search-button’).click(function(){

&#036;('.search-form').toggle();


return false;

});

$(’.search-form form’).submit(function(){

&#036;('#users-grid').yiiGridView('update', {


	data: &#036;(this).serialize()


});


return false;

});

$(’.deleteall-button’).click(function(){

    var atLeastOneIsChecked = &#036;('input[name=&#092;&quot;users-grid_c1[]&#092;&quot;]:checked').length &gt; 0;





    if (&#33;atLeastOneIsChecked)


    {


            alert('Please select atleast one Campaign to delete');


    }


    else if (window.confirm('Are you sure you want to delete the Campaign?'))


    {


            document.getElementById('users-form').action='index.php?r=users/DeleteAll';


            document.getElementById('users-form').submit();


    }

});

");

?>

<h1>Manage Users</h1>

<!–<p>

You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>

or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.

</p>–>

<?php echo CHtml::link(‘Advanced Search’,’#’,array(‘class’=>‘search-button’)); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial(’_search’,array(

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

)); ?>

</div><!-- search-form -->

<div class="wide form">

<?php $form=$this->beginWidget(‘CActiveForm’, array(

    'id'=&gt;'users-form',


    'enableAjaxValidation'=&gt;false,


    'htmlOptions'=&gt;array('enctype' =&gt; 'multipart/form-data')

));

?>

<!-------date ficker---->

<?php $form=$this->beginWidget(‘CActiveForm’, array(

'id'=&gt;'users-form',


'enableAjaxValidation'=&gt;true,

)); ?>

<b>From :</b>

<?php

$this->widget(‘zii.widgets.jui.CJuiDatePicker’, array(

'name'=&gt;'from_date',  // name of post parameter


'value'=&gt;Yii::app()-&gt;request-&gt;cookies['from_date']-&gt;value,  // value comes from cookie after submittion


 'options'=&gt;array(


    'showAnim'=&gt;'fold',


    'dateFormat'=&gt;'yy-mm-dd',


),


'htmlOptions'=&gt;array(


    'style'=&gt;'height:20px;'


),

));

?>

<b>To :</b>

<?php

$this->widget(‘zii.widgets.jui.CJuiDatePicker’, array(

'name'=&gt;'to_date',


'value'=&gt;Yii::app()-&gt;request-&gt;cookies['to_date']-&gt;value,


 'options'=&gt;array(


    'showAnim'=&gt;'fold',


    'dateFormat'=&gt;'yy-mm-dd',





),


'htmlOptions'=&gt;array(


    'style'=&gt;'height:20px;'


),

));

?>

<?php echo CHtml::submitButton(‘Go’); ?> // submit button

<?php $this->endWidget(); ?>

<!-------end date ficker--------->

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

'id'=&gt;'users-grid',


// 'selectableRows'=&gt;2,


'dataProvider'=&gt;&#036;model-&gt;search(),


'filter'=&gt;&#036;model,


'columns'=&gt;array(


 array('header' =&gt; '#', 'value' =&gt; '(&#036;row+1) . &quot;.&quot;', 'htmlOptions' =&gt; array('style' =&gt; 'text-align:right;')),


                         array(


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


           'class'=&gt;'CCheckBoxColumn',


		   // 'id'=&gt;'person-id',


		   'selectableRows' =&gt; '50',  


  


            ),


	  array(


'name'=&gt;'id',


'value'=&gt;'CHtml::encode(&#036;data-&gt;id)'

),

array(

'name'=&gt;'username',


'value'=&gt;'CHtml::encode(&#036;data-&gt;username)'

),

array(

'name'=&gt;'image',


'value'=&gt;'CHtml::encode(&#036;data-&gt;image)'

),

array(

'name'=&gt;'createtime',


'value'=&gt;'CHtml::encode(date(&#092;'Y-m-d,H:i:s&#092;', &#036;data-&gt;createtime))'  //this will format the unix timestamp to a custom date format

),

array(

 'name'=&gt;'lastvisit',              


 'value'=&gt;'CHtml::encode(date(&#092;'Y-m-d&#092;', &#036;data-&gt;lastvisit))'      // format the cell with date format

),

array(

 'name'=&gt;'status',


 'value'=&gt;'CHtml::encode(&#036;data-&gt;status==1 ? &#092;'Active&#092;': &#092;'Inactive&#092;' )' 

// to render the gridview cell with a particular value

),


array(


		'class'=&gt;'CButtonColumn',


		//y'afterDelete'=&gt;'function(link,success,data){ if(success) &#036;(&quot;#statusMsg&quot;).html(data); }',


		 


	),


),


  'selectionChanged'=&gt;'userClicks',

)); ?>

<div class="row buttons">

    &lt;?php echo CHtml::button('Delete',array('name'=&gt;'btndeleteall','class'=&gt;'deleteall-button')); ?&gt;

</div>

<?php $this->endWidget(); ?>

</div>

In controoler:

public function actionDeleteAll()

   {


	   


            


	  


    	if(Yii::app()-&gt;request-&gt;isPostRequest)


       {


		


            &#036;del_camps = &#036;_POST['users-grid_c1'];


			//print_r(&#036;del_camps);


			//echo &#036;_POST['person-id'];


			//exit();


			


            


            &#036;model_camp=new Users;


            //&#036;model_receipiant = new Recipiants;


            


            foreach (&#036;del_camps as &#036;_camp_id)


            {


                    &#036;model_camp-&gt;deleteByPk(&#036;_camp_id);


                    //&#036;model_receipiant-&gt;deleteAllByAttributes(array('camp_id'=&gt;&#036;_camp_id));


            }


                                    


            &#036;this-&gt;actionAdmin();


    }


    else


    {


            Yii::app()-&gt;user-&gt;setFlash('error', 'Please select at least one record to delete.');


			//echo 'sssss';


			//exit();


            &#036;this-&gt;actionAdmin();


    }               

}

pls help me

Simple and easiest process to delete a selected rows from grid is submit a form and collect a selected rows id then right a code to delete that ids in controller and redirect again on the same page.

Something like this




In Controller file

	if(!empty($_POST['targetListId'])){

			$targetlistArr=array('campaignId'=>$_POST['campaignId'],'targetListIds'=>$_POST['targetListId']);

			//Code to save Contact for TargetList

		    CampaignTargetlist::model()->removeTargetlistFromCampaign($targetlistArr);

		    Yii::app()->user->setFlash('success', "Target Lists for Campaign ' $campaignInfo->name ' Removed Successfully.");

			$this->redirect(array('campaign/view','id'=>$id));

		}



I hope you can understand my point.

Thanks for fast replay

its not working .i think i made a mistake

please give small example about delete all button in cgride view

Could you please tell me what you think where is a problem. IS it in PHP code or Jquery Code.Since i can not understand your code here Please paste it in code tag then post it.So, that i can check a code and suggest you the solution.

please give the example help me

In controller actionDeleteAll() method i am not getting checked values in view

public function actionDeleteAll()

{

if(Yii::app()->request->isPostRequest)

{

$del_camps = $_POST[‘users-grid_c1’];

//print_r($del_camps);

//echo $_POST[‘person-id’];

//exit();

$model_camp=new Users;

//$model_receipiant = new Recipiants;

foreach ($del_camps as $_camp_id)

{

$model_camp->deleteByPk($_camp_id);

//$model_receipiant->deleteAllByAttributes(array(‘camp_id’=>$_camp_id));

}

$this->actionAdmin();

}

else

{

Yii::app()->user->setFlash(‘error’, ‘Please select at least one record to delete.’);

//echo ‘sssss’;

//exit();

$this->actionAdmin();

}

}

PLS GIVE SOLUTION ANYBODY


	 <?php 

					  echo CHtml::beginForm('','post',array('id'=>'campaign-targetlist-form'));

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

						    'dataProvider'=>$dataprovider,

						   // 'filter'=>$model,

						    'emptyText'=>'There is no Targetlist is assigned for this Campaign',

						   // 'id'=>'evidenceId',

						    'selectableRows'=>2, // multiple rows can be selected

						    //'summaryText' => '{count} records(s) found.',

						     'summaryText' => '',

						  //  'template'=>"{pager}\n{items}\n{pager}", //To show pager on top

						   // 'template'=>"{pager}\n{items}", //To show pager on top

						    'columns'=>array(

						        array(

						            'class'=>'CCheckBoxColumn',

						            'id'=>'targetListId',

						            'value'=>'$data->id',

						        ),

						   array('name'=>'targetListName','value'=>'$data->targetListInfo->name'),

						   array('type'=>'raw','value'=>'CHtml::link("View TargetList",array("targetlist/view","id"=>$data->targetListInfo->id))'),

						   ), 	 

						));

						echo CHtml::hiddenField('campaignId',$campaignInfo->id);

						echo CHtml::submitButton('Remove TargetList',array('style'=>'margin-top:15px;background-color:#CCCCCC;'));

						echo CHtml::endForm();

						?>

Ok so this is my code for cgrid view. and in that code you can see that i have created a CCheckBoxcolumn. with this




  array(

						            'class'=>'CCheckBoxColumn',

						            'id'=>'targetListId',

						            'value'=>'$data->id',

						        ),



So when you will dump $_POST as my previous given code you can get a seleted ids.

please try this. And it is working for sure for me.