PHP code example of ropendev / datatablesphp

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

    

ropendev / datatablesphp example snippets


DataTable::instance('id')
    ->setJsInitParam($key, $value)           // http://datatables.net/reference/option/
    ->setJsInitParams($params)               // To set all params in one time
    ->setDom($dom)                           // Alias for setJsInitParameter('dom', $dom)
    ->setColumn($params, $show = true)       // Add a column and there options to the table:
                                             // - Initialization Javascript Options (see the doc : DataTables.net > Refererences > Column)
                                             //  - PHP Options (parent for complex header, sFilter, sql_table, sqlFilter... see l.169)
                                             // if($show) will be printed in the table else will only be load via ajax
    ->setColumns($columns)                   // Add columns
    ->setServerSide($ajax)                   // http://datatables.net/reference/option/ajax
    ->setAjax($ajax)                         // Alias for setJsInitParameter('ajax', $ajax)
    ->setFilters($ajax)                      // Set permanent filters for sql queries (where)
    ->setData($data)                         // Permit to set the data in the DataTables Javascript Initialization.
    ->setHeader($bool)                       // To generate thead when you will call getHtml
    ->setFooter($bool)                       // To generate tfoot with th empty when you will call getHtml.
                                             // ... automatically called if you have set individual column filters


DataTable::instance('id')->getJavascript();  // Return javascript string. It is not embeding JS Files from DataTables.js... only it activation
                                            // and individual column filtering stuff

DataTable::instance('id')->getHtml([array('class'=>'my_table_class', 'data-nuclear'=>'bomb')]);        // Return html table in a string

/*** Server-Side Functions ***/
# You can't use server side options if you didn't set Columns

DataTable::instance('id')
    ->setFrom($table)                                                                                                 // Name of the table to query
    ->setJoin('table2', array('table'=>'column', 'table2'=>'column2') [, $join = 'LEFT JOIN', $duplicate = false])    // Table to join
    ->setPdoLink($pdoLink)                                                                                            // Add PHP PDO class link
    ->setCounterActive(false)  // Disabled counters (permits to gain in performanche, think to change your infoFiltered)

DataTable::instance('id')->exec($_REQUEST[, $csv = false]);  // Output the json results
                                                             //or export to csv format (use setInitFilter before if you use Individual column Filters)
DataTable::instance('id')->sendFatal($error);                // Output an error