PHP code example of nineinchnick / edatatables

1. Go to this page and download the library: Download nineinchnick/edatatables 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/ */

    

nineinchnick / edatatables example snippets


'import' => array(
        ...
        'ext.edatatables.*', //if it's in your extensions folder
        'vendor.nineinchnick.edatatables.*', //if you're using composer (and have a 'vendor' alias!)
        ...
)

$widget = $this->createWidget('ext.edatatables.EDataTables', array(
 'id'            => 'products',
 'dataProvider'  => $dataProvider,
 'ajaxUrl'       => $this->createUrl('/products/index'),
 'columns'       => $columns,
));
if (!Yii::app()->getRequest()->getIsAjaxRequest()) {
  $this->render('index', array('widget' => $widget,));
  return;
} else {
  echo json_encode($widget->getFormattedData(intval($_REQUEST['sEcho'])));
  Yii::app()->end();
}

 $widget->run(); 

$criteria = new CDbCriteria;
// bro-tip: $_REQUEST is like $_GET and $_POST combined
if (isset($_REQUEST['sSearch']) && isset($_REQUEST['sSearch']{0})) {
    // use operator ILIKE if using PostgreSQL to get case insensitive search
    $criteria->addSearchCondition('textColumn', $_REQUEST['sSearch'], true, 'AND', 'ILIKE');
}

$sort = new EDTSort('ModelClass', $sortableColumnNamesArray);
$sort->defaultOrder = 'id';
$pagination = new EDTPagination();

$dataProvider = new CActiveDataProvider('ModelClass', array(
    'criteria'      => $criteria,
    'pagination'    => $pagination,
    'sort'          => $sort,
))

'EDataTables' => array(
    'htmlOptions' => array('class' => ''),
    'itemsCssClass' => 'table table-striped table-bordered table-condensed items',
    'pagerCssClass' => 'paging_bootstrap pagination',
    'buttons' => array(
        'refresh' => array(
            'tagName' => 'a',
            'label' => '<i class="icon-refresh"></i>',
            'htmlClass' => 'btn',
            'htmlOptions' => array('rel' => 'tooltip', 'title' => Yii::t('EDataTables.edt',"Refresh")),
            'init' => 'js:function(){}',
            'callback' => 'js:function(e){e.data.that.eDataTables("refresh"); return false;}',
        ),
    ),
    'datatableTemplate' => "<><'row'<'span3'l><'dataTables_toolbar'><'pull-right'f>r>t<'row'<'span3'i><'pull-right'p>>",
    'registerJUI' => false,
    'options' => array(
        'bJQueryUI' => false,
        'sPaginationType' => 'bootstrap',
        //'fnDrawCallbackCustom' => "js:function(){\$('a[rel=tooltip]').tooltip(); \$('a[rel=popover]').popover();}",
    ),
    'cssFiles' => array('bootstrap.dataTables.css'),
    'jsFiles' => array(
        'bootstrap.dataTables.js',
        'jdatatable.js' => CClientScript::POS_END,
    ),
),