This lib allows to process DataTable data content from server-side using PHP
composer require emagombe/datatable
Clone the project or download a release from https://github.com/emagombe/datatable/releases And import autoload.php file to you project
require_once 'autoload.php';
In the static method create pass the PDOStatement object then call the build object method to execute and return the output
use emagombe\DataTable;
$sql = "SELECT * FROM table;";
$stmt = $conn->prepare($sql);
$dt = DataTable::create($stmt)->build();
echo $dt;
Same as above, pass a array to the static method create then call the build object method to execute and return the output
use emagombe\DataTable;
$array = [];
$dt = DataTable::create($array)->build();
echo $dt;
Use the stream method to print the response
DataTable::create($result)->stream();
Call the object method addColumn to add a custom column. This method receives the current row as parameter;
Note: The callback should return a string containing the custom content of the column!
$dt = DataTable::create($result)->addColumn("action", function($row) {
return "<b>".$row["name"]."</b>";
})->build();
order | data type |
---|---|
first | string |
second | method |