mdmsoft/yii2-widgets

Widgets for Yii2

Installs: 7 087

Dependents: 1

Suggesters: 0

Security: 0

Stars: 17

Watchers: 9

Forks: 7

Open Issues: 1

Type:yii2-extension

1.4 2020-10-20 05:29 UTC

This package is not auto-updated.

Last update: 2024-12-11 01:08:52 UTC


README

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require mdmsoft/yii2-widgets "~1.0"

or add

"mdmsoft/yii2-widgets": "~1.0"

to the require section of your composer.json file.

Usage

TabularInput Widget

_form.php

<?php $form = ActiveForm::begin()?>
<table class="table">
    <thead>
        <tr>
            <th>&nbsp;</th>
            <th>&nbsp;</th>
            <th><a id="btn-add"><span class="glypicon glypicon-plus"></span></a></th>
        </tr>
    </thead>
<?= 
    TabularInput::widget([
        'id' => 'detail-grid',
        'allModels' => $model->items,
        'model' => OrderItem::className(),
        'tag' => 'tbody',
        'form' => $form,
        'itemOptions' => ['tag' => 'tr'],
        'itemView' => '_item_detail',
        'clientOptions' => [
            'btnAddSelector' => '#btn-add',
        ]
    ]);
?>
</table>

_item_detail.php

<td><?= $form->field($model,"[$key]product_id")->textInput()->label(false); ?></td>
<td><?= $form->field($model,"[$key]qty")->textInput()->label(false); ?></td>
<td><a data-action="delete"><span glypicon glypicon-minus></span></a></td>

GridInput Widget

<?= 
    GridInput::widget([
        'id' => 'detail-grid',
        'allModels' => $model->items,
        'model' => OrderItem::className(),
        'columns' => [
            ['class' => 'mdm\widgets\SerialColumn'],
            'product_id',
            'qty',
            [
                'attribute' => 'uom_id',
                'items' => [
                    1 => 'Pcs',
                    2 => 'Dozen'
                ]
            ],
            [
                'attribute' => 'tax',
                'type' => 'checkbox',
            ],
            ['class' => 'mdm\widgets\ButtonColumn']
        ],
    ]);
?>