Minggu, 19 Maret 2017

Cgridview

Model
public function statusBarang($i)
 {
  if($i==1)
   return "Belum diproses";
  else if($i==2)
   return "Sedang diproses";
  else 
   return "Sudah diproses";
 }
Controller
$this->widget('zii.widgets.grid.CGridView', array(
 'id'=>'junction-tab-grid',
 'dataProvider'=>$model->search(),
 'columns'=>array(
  'id',
  'kodeBarang',
  array(
   'name'=>'Nama Mahasiswa',
   'type'=>'raw',
   'value'=>'Barang::model()->statusBarang($data->statusBarang)',
  ),
  array(
   'class'=>'CButtonColumn',
  ),
 ),
));

CGridView

  array(
    'class'=>'CButtonColumn',
    'template'=>'{update}{add}{delete}',
    'buttons'=>array(
      'update'=>array(
          'url'=>'$this->grid->controller->createUrl("/Extras/update", array("id"=>$data->id,"asDialog"=>1,"gridId"=>$this->grid->id))',
          'click'=>'function(){$("#cru-frame").attr("src",$(this).attr("href")); $("#cru-dialog").dialog("open");  return false;}',
            'visible'=>'($data->id===null)?false:true;'
          ),
      'add' => array(
          'label'=>'Add',
          'imageUrl'=>Yii::app()->request->baseUrl.'/css/gridViewStyle/images/gr-plus.png',
          'url'=>'$this->grid->controller->createUrl("/Extras/create", array("eid"=>$data->extras_id, "bid"=>'.$model->id.', "asDialog"=>1,"gridId"=>$this->grid->id))',
          'click'=>'function(){$("#cru-frame").attr("src",$(this).attr("href")); $("#cru-dialog").dialog("open");  return false;}',
          'visible'=>'($data->id===null)?true:false;'
          ),
      'delete'=>array(
          'url'=>'$this->grid->controller->createUrl("/Extras/delete", array("id"=>$data->primaryKey,"asDialog"=>1,"gridId"=>$this->grid->id))',
          ),
    ),
  ),

CGridView

 $this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'bookings-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        'id',
        'name',
        'email',
        'telephone',
        'time',
        'employee',
        'appointment_status',
        'client_ip',
        'link' => array(
            'header' => 'Confirmation',
            'type' => 'raw',
            'value' => function ($data) {
                if ($data->appointment_status == 1) {
                    return CHtml::button("$data->appointment_status", array("onclick" => "document.location.href=\'" . Yii::app()->controller->createUrl("controller/action", array("id" => $data->id)) . "\'"));
                } else {

                    return;
                }
            }
                ),
                array(
                    'class' => 'CButtonColumn',
                ),
            ),
        ));