定制 rootlocal/yii2-sortable-grid-view 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rootlocal/yii2-sortable-grid-view

最新稳定版本:v2.0.6

Composer 安装命令:

composer require rootlocal/yii2-sortable-grid-view

包简介

Sortable Grid View

README 文档

README

Latest Stable Version

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2022-09-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固