PHP code example of jlorente / yii2-datatables

1. Go to this page and download the library: Download jlorente/yii2-datatables library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jlorente / yii2-datatables example snippets


use jlorente\datatables\grid\DataTables;

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

DataTables::widget([
    //Other configurations
    '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")
                ],
            ]
        ]
    ],
]);

public $depends = [
...
    'jlorente\datatables\assets\DataTablesAsset',
...
];
bash
$ php composer.phar