rklandesverband/yii2-datatables

Datatables widget for Yii2 uses datatables

Installs: 1 017

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.1 2021-02-17 14:31 UTC

This package is auto-updated.

Last update: 2024-11-17 22:58:17 UTC


README

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

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.

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 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.

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'],
    ],
]);?>

This extension uses the Bootstrap 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"=>[
        "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")
            ],
        ]
    ]
],
...

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 = [
...
'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/packages/rklandesverband/yii2-imagecropmassenupload)
[![Total Downloads](https://poser.pugx.org/rklandesverband/yii2-imagecropmassenupload/downloads)](https://packagist.org/packages/rklandesverband/yii2-imagecropmassenupload)
[![Latest Unstable Version](https://poser.pugx.org/rklandesverband/yii2-imagecropmassenupload/v/unstable)](https://packagist.org/packages/rklandesverband/yii2-imagecropmassenupload)
[![License](https://poser.pugx.org/rklandesverband/yii2-imagecropmassenupload/license)](https://packagist.org/packages/rklandesverband/yii2-imagecropmassenupload)

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

The preferred way to install this extension is through [composer](http://getcomposer.org/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'],
    ],
]);?>

This extension uses the Bootstrap 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"=>[
        "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")
            ],
        ]
    ]
],
...

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 = [
...
'rklandesverband\datatables\DataTablesAsset',
...
];
>>>>>>> c0bc5c12dfb9197055a648045d168c4325b342c8