2017 © Pedro Peláez
 

yii2-extension yii2-datatables

Yii2 Extension for DataTables jQuery plug-in

image

specifi/yii2-datatables

Yii2 Extension for DataTables jQuery plug-in

  • Wednesday, February 21, 2018
  • by salaros
  • Repository
  • 5 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 33 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Yii2 DataTables

Yii2 Widget for DataTables plug-in for jQuery, (*1)

Work in Progress. Not ready for production, (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

composer require "nullref/yii2-datatables" "*"

or add, (*5)

"nullref/yii2-datatables": "*"

to the require section of your composer.json file., (*6)

Basic Usage

<?= \nullref\datatable\DataTable::widget([
    'data' => $dataProvider->getModels(),
    'columns' => [
        'id',
        'name',
        'email'
    ],
]) ?>
    <?= \nullref\datatable\DataTable::widget([
        'columns' => [
            //other columns
            [
                'class' => 'nullref\datatable\LinkColumn',
                'url' => ['/model/delete'],
                'options' => ['data-confirm' => 'Are you sure you want to delete this item?', 'data-method' => 'post'],
                'queryParams' => ['id'],
                'label' => 'Delete',
            ],
        ],
    ]) ?>

Properties of LinkColumn:, (*7)

  • label - text placed in a tag;
  • url - will be passed to Url::to();
  • options - HTML options of the a tag;
  • queryParams - array of params added to url

Styling

DataTables supports several styling solutions, including Bootstrap, jQuery UI, Foundation., (*8)

'assetManager' => [
    'bundles' => [
        'nullref\datatable\DataTableAsset' => [
            'styling' => \nullref\datatable\DataTableAsset::STYLING_BOOTSTRAP,
        ]
    ],
],

Custom assets

It's posible to use custom styles and scripts:, (*9)

'nullref\datatable\DataTableAsset' => [
    'sourcePath' => '@webroot/js/plugin/datatables/',
    'js' => [
        'jquery.dataTables-1.10-cust.js',
        'DT_bootstrap.js',
    ],
    'css' => [
        'data-table.css',
    ],
    'styling' => false,
]

Server-side processing

To enable server-side processing add DataTableAction to controller like this:, (*10)

 class SomeController extends Controller
 {
     public function actions()
     {
         return [
             'datatables' => [
                 'class' => 'nullref\datatable\DataTableAction',
                 'query' => Model::find(),
             ],
         ];
     }

}

Searching and ordering can be customized using closures, (*11)

public function actions()
{
    return [
         'datatables' => [
             'class' => 'nullref\datatable\DataTableAction',
             'query' => Model::find(),
             'applyOrder' => function($query, $columns, $order) {
                //custom ordering logic
                return $query;
             },
             'applyFilter' => function($query, $columns, $search) {
                //custom search logic
                return $query;
             },
         ],
    ];
}

In DataTable options specify:, (*12)

{
    "serverSide": true,
    "ajax": "/datatables"
}

The Versions

21/02 2018

dev-master

9999999-dev https://github.com/NullRefExcep/yii2-datatables

Yii2 Extension for DataTables jQuery plug-in

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • yiisoft/yii2 ~2.0
  • bower-asset/datatables ~1.10
  • bower-asset/datatables-plugins ~1.0

 

plugin yii2 jquery datatables yii widget datatable

21/02 2018

1.1.0

1.1.0.0 https://github.com/NullRefExcep/yii2-datatables

Yii2 Extension for DataTables jQuery plug-in

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • yiisoft/yii2 ~2.0
  • bower-asset/datatables ~1.10
  • bower-asset/datatables-plugins ~1.0

 

plugin yii2 jquery datatables yii widget datatable

15/05 2017

v1.0.3

1.0.3.0 https://github.com/NullRefExcep/yii2-datatables

Yii2 Extension for DataTables jQuery plug-in

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • yiisoft/yii2 ~2.0
  • bower-asset/datatables.net ~1.10
  • bower-asset/datatables.net-plugins ~1.0

 

plugin yii2 jquery datatables yii widget datatable

10/08 2016

v1.0.2

1.0.2.0 https://github.com/NullRefExcep/yii2-datatables

Yii2 Extension for DataTables jQuery plug-in

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • yiisoft/yii2 ~2.0
  • bower-asset/datatables ~1.10
  • bower-asset/datatables-plugins ~1.0

 

plugin yii2 jquery datatables yii widget datatable

11/05 2016

v1.0.1

1.0.1.0 https://github.com/NullRefExcep/yii2-datatables

Yii2 Extension for DataTables jQuery plug-in

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • yiisoft/yii2 ~2.0
  • bower-asset/datatables ~1.10
  • bower-asset/datatables-plugins ~1.0

 

plugin yii2 jquery datatables yii widget datatable

07/07 2015

1.0

1.0.0.0 https://github.com/NullRefExcep/yii2-datatables

Yii2 Extension for DataTables jQuery plug-in

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • yiisoft/yii2 ~2.0
  • bower-asset/datatables ~1.10
  • bower-asset/datatables-plugins ~1.0

 

plugin yii2 jquery datatables yii widget datatable