У меня есть таблица MySQL со многими полями и двумя полями даты created_at
и updated_at
.
Мне нужен столбец в DataTables, имеющий разницу во времени между этими двумя полями.
Я использую опцию serverSide:true
для DataTables и ssp.class.php
.
Ниже мой код.
<?php
error_reporting("E_ALL");
if (isset($_GET['ajax'])) {
$table = 'table_here';
// Table's primary key
$primaryKey = 'id';
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
array('db' => 'type', 'dt' => 0),
array('db' => 'uniqueid', 'dt' => 1),
array('db' => 'created_at', 'dt' => 8),
array('db' => 'updated_at', 'dt' => 9), );
require('ssp.class.php');
echo json_encode(
SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns));
exit();
}
?>
$(document).ready(function () {
const table = $('#example').DataTable({
"columnDefs": [{
"targets": [7],
"visible": false,
}
],
"processing": true,
"serverSide": true,
"ajax": "url"
});
});