Complete Tutor: Working With Cgridview In Admin Panel

Hello everyone…

I’m newbie at Yii. Can anyone show me what less at this tutorial:

www.yiiframework.com/wiki/353/working-with-cgridview-in-admin-panel

This is my step:

  1. Add new field at the database idDelete (Bool)

  2. At my view (views/tabelAlumni/admin.php):


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

    'enableAjaxValidation'=>true,

)); ?>


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

	'id'=>'tabel-alumni-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		array(

            'id'=>'autoId',

            'class'=>'CCheckBoxColumn',

            'selectableRows' => '50',   

        ),

		'username',

		'nama_lengkap',

		'nama_panggilan',

		array(

			'name' => 'id_ps',

			'type' => 'HTML',

			'value' => '$data -> TabelPs -> nama_ps', 'sortable' => TRUE,

			'filter' => CHtml::listData (TabelPs::model() -> findAll(), 'id', 'nama_ps')

		),

		'angkatan',

		array(

			'name'=>'level',

			'type'=>'HTML',

			'filter'=>array('0'=>'Member', '1'=>'Moderator', '8'=>'Admin', '9'=>'Super Admin'),

			'value'=>'Yii::app()->user->getUserLabel($data->level)', 'sortable'=>TRUE,

		),

		

		array(

			'name'=>'aktif',

			'type'=>'HTML',

			'filter'=>array('0'=>'No', '1'=>'Yes'),

			'value'=>'CHtml::link(CHtml::encode($data->aktif=="0")?("No")<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />"Yes"), array("aktifUser", "id"=>$data->id))', 'sortable'=>TRUE,

			),

		

		array(

			'class'=>'CButtonColumn',

		),

	),

)); 

?>


<script>

function reloadGrid(data) {

    $.fn.yiiGridView.update('tabel-alumni-grid');

}

</script>

<?php echo CHtml::ajaxSubmitButton('Filter',array('menu/ajaxupdate'), array(),array("style"=>"display:none;")); ?>

<?php echo CHtml::ajaxSubmitButton('Delete',array('menu/ajaxupdate','act'=>'doDelete'), array('success'=>'reloadGrid')); ?>

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

  1. At my controller (TabelAlumniControlller.php)

	...

        public function actionAjaxupdate()

	{

		$act = $_GET['act'];

		if($act=='doSortOrder')

		{

			$sortOrderAll = $_POST['sortOrder'];

			if(count($sortOrderAll)>0)

			{

				foreach($sortOrderAll as $menuId=>$sortOrder)

				{

					$model=$this->loadModel($menuId);

					$model->sortOrder = $sortOrder;

					$model->save();

				}

			}

		}

		else

		{           

			$autoIdAll = $_POST['autoId'];

			if(count($autoIdAll)>0)

			{

				foreach($autoIdAll as $autoId)

				{

					$model=$this->loadModel($autoId);

					if($act=='doDelete')

						$model->isDeleted = '1';

					if($model->save())

						echo 'ok';

					else

						throw new Exception("Sorry",500);

	 

				}

			}

		}

	}

        ...

        

CheckBox and Delete button is show up, but not functioning. So pls tell me what i miss.

Thank you very much.

Hello Bro,

I think you missed to add your new column name into particular model. You need to add it under rule() function

Thanks :rolleyes:

Thanks for the reply. :)

My TabelAlumni model, Like this?? :


public function rules()

{

 return array(

  array('isDelete', 'length', 'max'=>2),

  ...



Still not working :(

I think the problem is here:


<?php echo CHtml::ajaxSubmitButton('Delete',array('menu/ajaxupdate','act'=>'doDelete'), array('success'=>'reloadGrid')); ?>

But i don’t know what i must to do??

Finally, i found another way, hehe

Thank you…