xlerr/yii2-common-widgets

1.5.3 2019-11-26 02:35 UTC

This package is auto-updated.

Last update: 2020-01-26 03:01:16 UTC


README

数据表格

基于DataTables

固定表头

echo \xlerr\common\widgets\DataTable::widget([
    'dataTableOptions' => [
        'fixedColumns' => [
            'leftColumns'  => 2,
            'rightColumns' => 1,
        ],
        'scrollY' => '300px', // 表格高度控制, 默认为: false
    ],
    'dataTableEvents'  => [
        'init.dt' => 'function () { console.log(\'init\'); }',
    ],
    'dataProvider' => new \yii\data\ArrayDataProvider([
        'allModels' => [],
    ]),
    'columns' => [],
]);

自定义格式化方法

注册

'components' => [
    'formatter' => [
        'as CustomFormatter' => \xlerr\common\behaviors\FormatterBehavior::class,
    ],
];

金额格式化

  • f2y|y2f 用法

    $formatter = \Yii::$app->getFormatter();
    $formatter->format(123456, ['f2y', true]); // string 1,234.56
    $formatter->format(123456, 'f2y'); // float 1234.56
    $formatter->format(1234.56, 'y2f'); // int 123456
  • f2y|y2f 用法 - \yii\grid\GridView

    'columns' => [
        [
            'format' => ['f2y', true],
            'attribute' => 'amount',
        ],
    ],

    amount647283, 输出字符串6,472.83

  • in 用法

    'columns' => [
        [
            'format' => ['in', ['open' => '打开', 'close' => '关闭'], 'defaultValue'],
            'attribute' => 'status', // print 打开|关闭|defaultValue
        ],
    ],

金额输入框

amount_input

amount字段值单位为分, 文本框内值的单位为元

$form->field($model, 'amount')->widget(\xlerr\common\widgets\MoneyInput::class, [
    'options' => [
        'placeholder' => '金额输入框',
    ],
]);

or

\xlerr\common\widgets\MoneyInput::widget([
    'name' => 'amount',
    'options' => [
        'placeholder' => '金额输入框',
    ],
]);

表单

提交表单等待效果

submit_waiting

echo \xlerr\common\widgets\ActiveForm::begin([
    'submitWaiting' => true,
]);