rikcage / yii2-grid-column-select
Show hide change position selected columns in grid, extension for Yii 2.0 Framework
Installs: 511
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2025-03-11 15:50:09 UTC
README
Show / hide change position selected columns in grid, extension for Yii 2.0 Framework
Installation
The preferred way to install this extension is through composer.
To install, either run
$ php composer.phar require rikcage/yii2-grid-column-select "*"
or add
"rikcage/yii2-grid-column-select": "*"
to the require
section of your composer.json
file.
Usage
in your views
use rikcage\grid_column_select\ColumnSelector;
use kartik\grid\GridView;
or
use yii\grid\GridView;
<?php
$columns = [
['class' => 'yii\grid\SerialColumn'],
['class' => 'yii\grid\ActionColumn'],
'id',
'title',
];
?>
<?php
$grid = ColumnSelector::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $columns,
'defaultShowColumns'=>[1, 0,], // default settinfs show first title after id
]);
echo $grid;
$columns = ColumnSelector::getShowColumns();
?>
<?php
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $columns,
]);
?>
if you want save selection of columns which user selected, in db you should add in your settings file (/common/config/main.php)
'modules' => [
...
'columnSelector' => [
'class' => 'rikcage\grid_column_select\ColumnSelector',
'params' => [
'userClass' => 'common\models\User', // models of user settings
'userid' => 'id', // field name which have user identity Yii::$app->user->identity->id
'settings_field' => 'params', // field name for save parameters which user selected
]
],
],