rklandesverband/yii2-datatables

Yii2 的 Datatables 小部件使用 datatables

安装: 970

依赖: 0

建议: 0

安全: 0

星级: 0

关注者: 2

分支: 0

开放问题: 0

类型:yii2-extension

1.0.1 2021-02-17 14:31 UTC

This package is auto-updated.

Last update: 2024-09-17 22:36:56 UTC


README

<<<<<<< HEAD DataTables widget for Yii2

此扩展为 Yii2 框架提供 DataTables 集成。

Latest Stable Version Total Downloads Latest Unstable Version License

安装

通过 composer 安装此扩展是首选方法。

安装 Composer 后,您可以使用以下命令安装扩展

composer global require "fxp/composer-asset-plugin:~1.0.0"
composer require --prefer-dist rklandesverband/yii2-datatables "*"

第一个命令安装 composer asset plugin,它允许通过 Composer 管理bower 和 npm 包依赖项。您只需要运行此命令一次。第二个命令安装 datatables 小部件。

您也可以将以下内容添加到(而不是第二个命令)

"rklandesverband/yii2-widget-datatables": "*"

到您的 composer.json 文件的 require 部分中。

用法

像使用其他任何 Yii2 小部件一样使用 DataTables。

use rklandesverband\datatables\DataTables;
<?php
    $searchModel = new ModelSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
?>
<?= DataTables::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],

        //columns

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

此扩展使用 Bootstrap 集成插件来提供默认的 Yii2 风格。

TableTools 插件也可用。在客户端选项数组中指定 DOM 和 tableTools 设置,如下例所示。

...
'clientOptions' => [
    "lengthMenu"=> [[20,-1], [20,Yii::t('app',"All")]],
    "info"=>false,
    "responsive"=>true, 
    "dom"=> 'lfTrtip',
    "tableTools"=>[
        "aButtons"=> [  
            [
            "sExtends"=> "copy",
            "sButtonText"=> Yii::t('app',"Copy to clipboard")
            ],[
            "sExtends"=> "csv",
            "sButtonText"=> Yii::t('app',"Save to CSV")
            ],[
            "sExtends"=> "xls",
            "oSelectorOpts"=> ["page"=> 'current']
            ],[
            "sExtends"=> "pdf",
            "sButtonText"=> Yii::t('app',"Save to PDF")
            ],[
            "sExtends"=> "print",
            "sButtonText"=> Yii::t('app',"Print")
            ],
        ]
    ]
],
...

您还可以在应用程序的 JavaScript 层中使用 DataTables。为此,您需要将 DataTables 作为 Asset 文件的依赖项包含。在这种情况下,您可以使用 yii\grid\GridView 或使用 datatables 选项 retrieve => true 来避免错误。在两种情况下,所有选项都必须在 JavaScript 对象中。

public $depends = [
...
'rklandesverband\datatables\DataTablesAsset',
...
];
=======
DataTables widget for Yii2
===========================
This extension provides the [DataTables](https://github.com/DataTables/DataTables) integration for the Yii2 framework.


[![Latest Stable Version](https://poser.pugx.org/rklandesverband/yii2-imagecropmassenupload/v/stable)](https://packagist.org.cn/packages/rklandesverband/yii2-imagecropmassenupload)
[![Total Downloads](https://poser.pugx.org/rklandesverband/yii2-imagecropmassenupload/downloads)](https://packagist.org.cn/packages/rklandesverband/yii2-imagecropmassenupload)
[![Latest Unstable Version](https://poser.pugx.org/rklandesverband/yii2-imagecropmassenupload/v/unstable)](https://packagist.org.cn/packages/rklandesverband/yii2-imagecropmassenupload)
[![License](https://poser.pugx.org/rklandesverband/yii2-imagecropmassenupload/license)](https://packagist.org.cn/packages/rklandesverband/yii2-imagecropmassenupload)

Installation
------------

The preferred way to install this extension is through [composer](http://getcomposer.org.cn/download/).

With Composer installed, you can then install the extension using the following commands:

    composer global require "fxp/composer-asset-plugin:~1.0.0"
    composer require --prefer-dist rklandesverband/yii2-datatables "*"

The first command installs the [composer asset plugin](https://github.com/francoispluchino/composer-asset-plugin/)
which allows managing bower and npm package dependencies through Composer. You only need to run this command
once for all. The second command installs the datatables widget.

You can also add (instead of the second command):

"rklandesverband/yii2-widget-datatables": "*"


to the require section of your `composer.json` file.

Usage
-----
Use DataTables as any other other Yii2 widget.

```php
use rklandesverband\datatables\DataTables;
<?php
    $searchModel = new ModelSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
?>
<?= DataTables::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],

        //columns

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

此扩展使用 Bootstrap 集成插件来提供默认的 Yii2 风格。

TableTools 插件也可用。在客户端选项数组中指定 DOM 和 tableTools 设置,如下例所示。

...
'clientOptions' => [
    "lengthMenu"=> [[20,-1], [20,Yii::t('app',"All")]],
    "info"=>false,
    "responsive"=>true, 
    "dom"=> 'lfTrtip',
    "tableTools"=>[
        "aButtons"=> [  
            [
            "sExtends"=> "copy",
            "sButtonText"=> Yii::t('app',"Copy to clipboard")
            ],[
            "sExtends"=> "csv",
            "sButtonText"=> Yii::t('app',"Save to CSV")
            ],[
            "sExtends"=> "xls",
            "oSelectorOpts"=> ["page"=> 'current']
            ],[
            "sExtends"=> "pdf",
            "sButtonText"=> Yii::t('app',"Save to PDF")
            ],[
            "sExtends"=> "print",
            "sButtonText"=> Yii::t('app',"Print")
            ],
        ]
    ]
],
...

您还可以在应用程序的 JavaScript 层中使用 DataTables。为此,您需要将 DataTables 作为 Asset 文件的依赖项包含。在这种情况下,您可以使用 yii\grid\GridView 或使用 datatables 选项 retrieve => true 来避免错误。在两种情况下,所有选项都必须在 JavaScript 对象中。

public $depends = [
...
'rklandesverband\datatables\DataTablesAsset',
...
];
>>>>>>> c0bc5c12dfb9197055a648045d168c4325b342c8