承接 reine/yii2-widget-datatables 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

reine/yii2-widget-datatables

最新稳定版本:v1.5.1

Composer 安装命令:

composer require reine/yii2-widget-datatables

包简介

DataTables widget for Yii2 with Bootstrap 4

README 文档

README

This extension provides the DataTables integration for the Yii2 framework.

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist reine/yii2-widget-datatables "^0.1.1"

or add

"reine/yii2-widget-datatables": "^0.1.1"

to the require section of your composer.json file.

Usage

Use DataTables as any other other Yii2 widget.

# In controller, prepare data that will be passed to the view:

    public function actionIndex()
    {
        $searchModel = new ModelSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $this->_pageSize);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

# In view:

<?php
use reine\datatables\DataTables;
?>
    <div class="row">
        <div class="col-12">

        <?= DataTables::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            // Optional (only if you want to override the defaults)
            'tableOptions' => [
                'class' => 'table card-table table-vcenter text-nowrap datatable',
            ],
            // Optional (only if you want to override the defaults)
            'clientOptions' => [
                "lengthMenu" => [[10,20,50,-1], [10,20,50,Yii::t('app',"All")]],
                "info" => true,
                "responsive" => true, 
                "dom" => 'lBfTrtip',
                "tableTools" => [],
                'buttons' => [
                    [
                        'extend' => 'copy',
                        'text'   => 'Copy to Clipboard'
                    ],
                    'excel',
                    'pdf'
                ],
            ],
            'columns' => [
                ['class' => 'yii\grid\SerialColumn'],

                //columns

                ['class' => 'yii\grid\ActionColumn'],
            ],
        ]);?>

        </div>
    </div>

This extension uses the Bootstrap 4 integration plugin to provide a Yii2 style by default.

The TableTools plugin is also available. Specify the DOM and the tableTools settings in the clientOptions array as the following example.

...
'clientOptions' => [
    "lengthMenu"=> [[20,-1], [20,Yii::t('app',"All")]],
    "info"=>false,
    "responsive"=>true, 
    "dom"=> 'lfTrtip',
    "tableTools"=>[
        //empty for load button assets
    ],
    'buttons'   => ['copy', 'excel', 'pdf'],
],
...

You can also use DataTables in the JavaScript layer of your application. To achieve this, you need to include DataTables as a dependency of your Asset file. In this case, you could use yii\grid\GridView or using the datatables options retrieve => true to avoid errors. In both case all options must be in the Javascript object.

public $depends = [
...
'reine\datatables\DataTablesAsset',
...
];

统计信息

  • 总下载量: 4.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 29
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-13