我是使用 DataTable 服务器端处理的新手。我很困惑在 Columns 数组中调用 PHP 函数。
这是前端代码。
<table id="memListTable" class="display" style="width:100%">
<thead>
<tr>
<th>Request Date</th>
<th>District Name</th>
<th>Request Type</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Request Date</th>
<th>District</th>
<th>Request Type</th>
</tr>
</tfoot>
</table>
<script>
$(document).ready(function(){
$('#memListTable').DataTable({
"processing": true,
"serverSide": true,
"aaSorting": [[0,'desc']],
"ajax": "getData.php"
});
});
</script>
获取数据.php
<?php
$dbDetails = array(
'host' => '****',
'user' => '****',
'pass' => '****',
'db' => '****'
);
$table = 'requestss';
$primaryKey = 'id';
$columns = array(
array( 'db' => 'time_stamp', 'dt' => 0 ),
array( 'db' => 'dist_code', 'dt' => 1),
array( 'db' => 'req_type', 'dt' => 2 )
);
// Include SQL query processing class
require( 'ssp.class.php' );
// Output data as json format
echo json_encode(
SSP::simple( $_GET, $dbDetails, $table, $primaryKey, $columns )
);
这两个文件都产生了完美的结果。输出
人到中年有点甜