xlerr / yii2-common-widgets
This package is abandoned and no longer maintained.
No replacement package was suggested.
This package has no released version yet, and little information is available.
README
数据表格
固定表头
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', ], ],
amount
为647283
, 输出字符串6,472.83
-
in 用法
'columns' => [ [ 'format' => ['in', ['open' => '打开', 'close' => '关闭'], 'defaultValue'], 'attribute' => 'status', // print 打开|关闭|defaultValue ], ],
金额输入框
amount
字段值单位为分, 文本框内值的单位为元
$form->field($model, 'amount')->widget(\xlerr\common\widgets\MoneyInput::class, [ 'options' => [ 'placeholder' => '金额输入框', ], ]);
or
\xlerr\common\widgets\MoneyInput::widget([ 'name' => 'amount', 'options' => [ 'placeholder' => '金额输入框', ], ]);
表单
提交表单等待效果
echo \xlerr\common\widgets\ActiveForm::begin([ 'submitWaiting' => true, ]);