Giix Controller with JToggleColumn

Hello If you are using JToggleColumn extension with GxController then the loadModel syntax look like following:

$this->loadModel($id, ‘ModelName’),

So if we want to use JToggleColumn extension following changes needed in extension so we can dynamically use toggle button.

changes in JToggleColumn.php

1. declare public variable called

public $model_name = null;

2. put following code in init() function for exception

 if ($this->model_name === null)
            throw new CException(Yii::t(‘toggle_column’, ‘Model attribute (“model_name”) must be specified for CToggleColumn.’));
 3. put following code in initDefaultButtons() function

$this->toggle_button = array(
                ‘url’ => ‘Yii::app()->controller->createUrl(“‘ . $this->action . ‘”,array(“id”=>$data->primaryKey,”attribute”=>”‘ . $this->name . ‘”,”model_name”=>”‘.$this->model_name.'”))’,
                ‘options’ => array(‘class’ => $this->name . ‘_toggle’),

changes in ToggleAction.php

public function run($id,$attribute,$model_name) {
            // we only allow deletion via POST request
            $model = $this->controller->loadModel($id,$model_name);
            $model->$attribute = ($model->$attribute==0)?1:0;
            // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
                $this->redirect(isset($_POST[‘returnUrl’]) ? $_POST[‘returnUrl’] : array(‘admin’));
        throw new CHttpException(400,’Invalid request. Please do not repeat this request again.’);

This is Done..

If you want to put togglebutton in gridview this the column code look like following…

                    ‘name’=>’active’, // boolean model attribute (tinyint(1) with values 0 or 1)
                    ‘model_name’=>’ModelName’,             //here is my model name so click on button change done in table related this model
                    ‘filter’ => array(‘1’ => ‘Yes’,’0′ => ‘No’), // filter
            ‘action’=>’toggle’, // other action, default is ‘toggle’ action
            ‘checkedButtonLabel’=>Yii::app()->baseUrl.’/images/checked.png’, // tooltip


So by this changes you can dynamically toggle the column value..



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s