Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

JToggleColumn

Column for CGridView which toggles the boolean ( TINYINT(1) ) value of model attribute. Tested with Yii 1.10.

Example

JToggleColumn

History

24.04.2012 - first release

25.04.2012 - added filter option and is now using assets

17.06.2012 - added ability to change action(two included: toggle(default) and switch), now using CActions

17.09.2012 - fixed bug with sorting, now sorts column in ajax way

Tutorial

Extract downloaded zip to your components or extensions directory.

If you extracted to extensions directory add this line to import array in your /config/main.php :

<?php

'import'=>array(
    ...
    'application.extensions.jtogglecolumn.*', 
)

?>

Define a JToggleColumn in your CGridView widget:

<?php

$this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'language-grid',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(
                'id',
                'name',
                'lang_code',
                'time_format',
                array(
                                'class'=>'JToggleColumn',
                                'name'=>'is_active', // boolean model attribute (tinyint(1) with values 0 or 1)
                                'filter' => array('0' => 'No', '1' => 'Yes'), // filter
                                'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
                ),
                array(
                                        'class'=>'JToggleColumn',
                                        'name'=>'is_default', // boolean model attribute (tinyint(1) with values 0 or 1)
                                        'filter' => array('0' => 'No', '1' => 'Yes'), // filter
                                        'action'=>'switch', // other action, default is 'toggle' action
                                        'checkedButtonImageUrl'=>'/images/toggle/yes.png', // checked image
                                        'uncheckedButtonImageUrl'=>'/images/toggle/no.png', // unchecked image
                                        'checkedButtonLabel'=>'No', // tooltip
                                        'uncheckedButtonLabel'=>'Yes', // tooltip
                                        'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;')
                ),
                array(
                        'class'=>'CButtonColumn',
                ),
        ),
));

?>

Add action(s) in your controller:

<?php

public function actions(){
    return array(
            'toggle'=>'ext.jtogglecolumn.ToggleAction',
            'switch'=>'ext.jtogglecolumn.SwitchAction', // only if you need it
    );
}

?>

Don't forget to add this action to controllers accessRules:

<?php

public function accessRules()
{
        return array(
                array('allow',
                        'actions'=>array('toggle','switch'),
                        'users'=>array('admin'),
                )
        );
}

?>

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.