rootlocal/yii2-sortable-grid-view
最新稳定版本:v2.0.6
Composer 安装命令:
composer require rootlocal/yii2-sortable-grid-view
包简介
Sortable Grid View
关键字:
README 文档
README
install
composer require rootlocal/yii2-sortable-grid-view
or added composer.json:
"rootlocal/yii2-sortable-grid-view": "~2.0"
Model Behavior
<?php namespace common\models; use rootlocal\widgets\sortable\SortableGridBehavior; class Book extends ActiveRecord { // ... /** * {@inheritDoc} */ public function behaviors(): array { return [ 'sort' => ['class' => SortableGridBehavior::class], // ... ]; } }
Query
<?php namespace common\models; use rootlocal\widgets\sortable\SortableGridQueryTrait; use yii\db\ActiveQuery; /** * This is the ActiveQuery class for [[Book]]. * * @see Book * @mixin SortableGridQueryTrait */ class BookQuery extends ActiveQuery { use SortableGridQueryTrait; // ... }
Controller
/** * {@inheritDoc} */ public function actions(): array { return [ 'sort' => [ 'class' => SortableGridAction::class, 'model' => Book::class, ] ]; }
Sorting
<?php $query = Book->find()->sortByOrder();
Example
<?php use common\models\BookSearch; use rootlocal\widgets\sortable\SortableGridColumnWidget; use yii\data\ActiveDataProvider; use yii\grid\GridView; use yii\web\View; /** * @var View $this * @var BookSearch $searchModel * @var ActiveDataProvider $dataProvider */ <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ [ 'class' => SortableGridColumnWidget::class, 'sortableWidgetOptions' => ['sortValueSelector' => '.sort_order'], ], // ... [ 'attribute' => 'sort_order', 'format' => 'raw', 'value' => fn(BookSearch $model) => Html::tag('span', $model->sort_order, [ 'class' => 'sort_order', ]), ], ]]) ?>
Extended config
<?php use common\models\BookSearch; use rootlocal\widgets\sortable\SortableGridColumnWidget; use yii\data\ActiveDataProvider; use yii\grid\GridView; use yii\web\View; use yii\helpers\Url; /** * @var View $this * @var BookSearch $searchModel * @var ActiveDataProvider $dataProvider */ <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ [ 'class' => SortableGridColumnWidget::class, 'template' => '{sort} {test}', 'sortableWidgetOptions' => [ // Sort action 'sortableAction' => Url::to(['/book/sort']) ], 'buttons' => [ 'test' => fn(BookSearch $model, $key) => '<i class="fa fa-address-book"></i>', ], 'visibleButtons' => [ 'test' => fn(BookSearch $model) => $model->status === $model::STATUS_TEST10, ], ], // ... ]]) ?>
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2022-09-09