DataTables widget for Yii2 ¶
This extension provides the DataTables integration for the Yii2 framework.
Installation ¶
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist fedemotta/yii2-widget-datatables "*"
or add
"fedemotta/yii2-widget-datatables": "*"
to the require section of your composer.json
file.
Usage ¶
Use DataTables as any other other Yii2 widget.
use fedemotta\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'],
],
]);?>
<?php
//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")
],
]
]
],
...
?>
<?php
//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.
public $depends = [
...
'fedemotta\datatables\DataTablesAsset',
...
];
?>
Not able to pull the packages. Having errors:
[ReflectionException]
Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist
[ErrorException]
Declaration of Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository
::whatProvides(Composer\DependencyResolver\Pool $pool, $name) should be com
patible with Composer\Repository\ComposerRepository::whatProvides(Composer\
DependencyResolver\Pool $pool, $name, $bypassFilters = false)
I have downloaded the fxp and not able to download 'fedemotta" widget. Though I have it downloaded via Git directly. Can you please tell me how to install manually?
Cool widget
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.