fgh151 / yii2-grid
Grid view with switchable columns
Package info
Type:yii2-extension
pkg:composer/fgh151/yii2-grid
v0.0.5
2026-08-24 09:55 UTC
Requires
- yiisoft/yii2: ^2.0.0
- yiisoft/yii2-bootstrap5: ^2.0.0
README
Grid view with swithcable columns
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist fgh151/yii2-grid "*"
or add
"fgh151/yii2-grid": "*"
to the require section of your composer.json file.
Usage
Once the extension is installed, simply use it in your code by :
use fgh151\yii\grid\GridView; /** * @var $dataProvider yii\data\ActiveDataProvider * @var $searchModel \yii\db\ActiveRecord */ $availableColumns = ['id', 'email', 'firstname', 'lastname']; $defaultColumns = ['id', 'email']; echo GridView::widget([ 'dataProvider' => $dataProvider, // required 'filterModel' => $searchModel, // default is null 'defaultColumns' => $defaultColumns, // default is [], if you want to use default columns 'availableColumns' => $availableColumns, // default is [], if you want to use default columns ]);
Trim column header
$availableColumns = [ [ // Default column header will be 'Column with long attribute label' // Or fetch from $model->getAttributeLabel('attribute') 'attribute' => 'column_with_long_attribute_label', // Now it will be 'Column with...' 'trim' => 10, ], ];