Wednesday, October 14, 2015

Yii Delete Records With Multi Check Box


Yii::app()->clientScript->registerScript('deleteall','
$("#deleteall").click(function(){
        var checked=$("#casecategory-grid").yiiGridView("getChecked","casecategory-grid_c0");
        var count=checked.length;
        if(count>0 && confirm("Do you want to delete these "+count+" item(s)"))
        {
                $.ajax({
                        data:{checked:checked},
                        url:"'.CHtml::normalizeUrl(array('Casecategory/removeall')).'",
                        success:function(data){$("#casecategory-grid").yiiGridView("update",{});},              
                });
        }
        });
');


$this->widget('zii.widgets.grid.CGridView', array( 'id'=>'casecategory-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array( array( 'class'=>'CCheckBoxColumn', //CHECKBOX COLUMN ADDED. 'selectableRows'=>2, //MULTIPLE ROWS CAN BE SELECTED. ), 'name', array( 'name'=>'parent', 'type'=>'raw', 'value'=>'$data->getparent ? $data->getparent->name : " No Parent"', // 'filter' => CHtml::listData(User::model()->findAll(), 'id', 'fullname'), ), array( 'class'=>'CButtonColumn', ), ), ));
echo CHtml::button("Remove Selected Items",array("id"=>"deleteall")); // Controller public function actionRemoveall() { if(Yii::app()->request->getIsAjaxRequest()) { $checkedIDs=$_GET['checked']; foreach($checkedIDs as $id) Casecategory::model()->deleteByPk($id); } }

No comments:

Post a Comment