taguz91/yii2-custom-columns

This columns is aplicable to grid view

1.0.0 2021-04-04 01:10 UTC

This package is auto-updated.

Last update: 2024-05-04 08:23:50 UTC


README

This columns is aplicable to grid view, for bootstrap 4

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

The preferred way to install this extension is through composer.

Either run

composer require taguz91/yii2-custom-columns

or add

"taguz91/yii2-custom-columns": "~1.0.0"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

GridView::widget([
  'dataProvider' => $dataProvider,
  'filterModel' => $searchModel,
  'columns' => [
    ['class' => 'yii\grid\SerialColumn'],
    [
      'class' => \taguz91\CustomColumns\ArrayValueColumn::class,
      'array' => ['1' => 'One', '2' => 'Two'],
      'default' => 'default',
      'attribute' => 'attribute',
    ],

    [
      'class' => \taguz91\CustomColumns\CashColumn::class,
      'attribute' => 'attribute',
    ],

    [
      'class' => \taguz91\CustomColumns\ImageColumn::class,
      'attribute' => 'attribute',
      'urlPrefix' => 'static/images',
    ],

    [
      'class' => \taguz91\CustomColumns\ModalColumn::class,
      'attribute' => 'attribute',
      'modalTitle' => 'Detail view',
      'render' => Url::to(['detail', 'id' => 1]),
    ],

    [
      'class' => \taguz91\CustomColumns\MongoDateColumn::class,
      'attribute' => 'attribute',
    ],

    [
      'class' => \taguz91\CustomColumns\PrefixColumn::class,
      'attribute' => 'attribute',
    ],

    [
      'class' => \taguz91\CustomColumns\ShowColumn::class,
      'attribute' => 'attribute',
      'redirectTo' => 'detail/view'
    ],

    [
      'class' => \taguz91\CustomColumns\SwitchColumn::class,
      'attribute' => 'attribute',
    ],

    [
      'class' => \taguz91\CustomColumns\SwitchColumn::class,
      'attribute' => 'attribute',
      'api' => 'api/v1/toggle', // This endpoint add the primarykey 
      'active' => true, // Condition for activate the toggle 
    ],

    [
      'class' => \taguz91\CustomColumns\UpdatedAtColumn::class,
    ],
  ],
]);

For \taguz91\CustomColumns\ModalColumn you need to include the modal widget in your layout

<?= \taguz91\CustomColumns\widgets\ModalAjax::widget() ?>

For \taguz91\CustomColumns\SwitchColumn::class you need to include the bootstrap4-toogle assets in your AppAsset

$depends = [
  ...,
  \taguz91\CustomColumns\assets\ToggleAsset::class
];