conquer / datatables
Yii2 datatables widget
Package info
github.com/borodulin/yii2-datatables
Type:yii2-extension
pkg:composer/conquer/datatables
Requires
- php: ^7.4 || ^8.0
- bower-asset/datatables.net: ^1.10.16
- bower-asset/datatables.net-autofill: ^2.2.2
- bower-asset/datatables.net-autofill-bs: ^2.2.2
- bower-asset/datatables.net-bs: ^1.10.16
- bower-asset/datatables.net-buttons: ^1.1.2
- bower-asset/datatables.net-buttons-bs: ^1.1.2
- bower-asset/datatables.net-colreorder: ^1.4.1
- bower-asset/datatables.net-colreorder-bs: ^1.4.1
- bower-asset/datatables.net-fixedcolumns: ^3.2.3
- bower-asset/datatables.net-fixedcolumns-bs: ^3.2.3
- bower-asset/datatables.net-fixedheader: ^3.1.3
- bower-asset/datatables.net-fixedheader-bs: ^3.1.3
- bower-asset/datatables.net-keytable: ^2.3.2
- bower-asset/datatables.net-keytable-bs: ^2.3.2
- bower-asset/datatables.net-plugins: ^1.10.16
- bower-asset/datatables.net-responsive: ^2.2.0
- bower-asset/datatables.net-responsive-bs: ^2.2.0
- bower-asset/datatables.net-rowgroup: ^1.0.2
- bower-asset/datatables.net-rowgroup-bs: ^1.0.2
- bower-asset/datatables.net-rowreorder: ^1.2.3
- bower-asset/datatables.net-rowreorder-bs: ^1.2.3
- bower-asset/datatables.net-scroller: ^1.4.3
- bower-asset/datatables.net-scroller-bs: ^1.4.3
- bower-asset/datatables.net-select: ^1.2.3
- bower-asset/datatables.net-select-bs: ^1.2.3
- yiisoft/yii2: ^2.0.6
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-03 04:14:17 UTC
README
Description
Yii2 integration of DataTables 1.10 with Bootstrap styling:
DatatablesWidgetrenders a table and initializes DataTables, registering only the extensions you use (AutoFill, Buttons, ColReorder, FixedColumns, FixedHeader, KeyTable, Responsive, RowGroup, RowReorder, Scroller, Select);DatatablesActionimplements the DataTables server-side processing protocol on top of a YiiQuery/ActiveQuery, including paging, ordering and global/per-column search.
The interface language is taken from Yii::$app->language automatically.
Requirements
- PHP 7.4 or 8.x
- Yii 2.0.6 or newer (2.0.x)
- asset-packagist repository configured in your application's
composer.json(standard for Yii2 app templates)
Installation
Install the extension via Composer:
composer require conquer/datatables:^1.1
Usage
Server-side processing
Controller:
use conquer\datatables\DatatablesAction; class UserController extends \yii\web\Controller { public function actions() { return [ 'datatables' => [ 'class' => DatatablesAction::class, 'query' => User::find(), // only these fields are sent to the browser 'attributes' => ['id', 'username', 'email'], // maximum rows per request (client "length", including -1, is capped) 'maxLength' => 500, ], ]; } }
For an ActiveQuery, searching and ordering are applied automatically to the columns that exist
in the table schema (LIKE for strings, = for numbers and booleans). For any other query,
or to customize the behavior, provide callbacks:
'filterCallback' => function ($query, $columns, $search) { /* ... */ }, 'orderCallback' => function ($query, $columns, $order) { /* ... */ },
query can also be a callable returning the query.
Security: without
attributesevery column selected by the query is returned to the client (forUser::find()that includes password hashes and tokens). Always setattributesor restrictselect().
View:
use conquer\datatables\DatatablesWidget; echo DatatablesWidget::widget([ 'ajax' => ['user/datatables'], 'columns' => [ 'id' => 'ID', 'username' => 'Username', 'email' => 'Email', ], 'tableOptions' => ['class' => 'table table-striped table-bordered'], 'responsive' => true, 'stateSave' => true, ]);
Keys of columns are the data fields, values are the column titles.
When ajax is set, serverSide is enabled by default.
Client-side data
echo DatatablesWidget::widget([ 'columns' => ['name' => 'Name', 'price' => 'Price'], 'data' => [ ['name' => 'Apple', 'price' => 1.2], ['name' => 'Orange', 'price' => 0.9], ], ]);
Options
Common DataTables options are available as widget properties: autoWidth, deferRender, info,
lengthChange, ordering, paging, processing, scrollX, scrollY, searching, stateSave.
Extension options (autoFill, buttons, colReorder, fixedColumns, fixedHeader, keys,
responsive, rowGroup, rowReorder, scroller, select) also register the corresponding assets.
Any other DataTables option can be passed via options.
License
conquer/datatables is released under the MIT License. See the bundled LICENSE for details.