Skip to content

Instantly share code, notes, and snippets.

@nrogap
Last active September 8, 2017 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nrogap/cfbef5ea8470d45dc5de9d1ad2cd6754 to your computer and use it in GitHub Desktop.
Save nrogap/cfbef5ea8470d45dc5de9d1ad2cd6754 to your computer and use it in GitHub Desktop.
ตัวอย่างการใช้งาน datatables js และ ssp.customized.class.php
SELECT
student_id,
first_name,
last_name,
CONCAT(first_name,' ',last_name) AS full_name,
FROM person p
INNER JOIN class_room cr
ON p.student_id = cr.student_id
WHERE
cr.class_room_name = '6/1'
AND cr.class_room_builder = 3
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "server-side-processing.php",
"type": "POST"
},
"columnDefs": [
{
"targets": [3],
"visible": true,
"searchable": false
}
]
});
});
<?php
$table = 'person';
$primaryKey = 'student_id';
$columns = array();
$columns[] = array('db' => 'p.student_id', 'dt' => 0, 'field' => 'student_id');
$columns[] = array('db' => 'p.first_name', 'dt' => 0, 'field' => 'first_name');
$columns[] = array('db' => 'p.last_name', 'dt' => 0, 'field' => 'last_name');
$columns[] = array('db' => 'CONCAT(first_name,' ',last_name)', 'dt' => 0, 'field' => 'full_name', 'AS' => 'full_nmae');
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'my_db',
'host' => 'localhost'
);
$joinQuery = "FROM person p
INNER JOIN class_room cr
ON p.student_id = cr.student_id
";
$extraWhere = "cr.class_room_name = '6/1'
AND cr.class_room_builder = 3
";
require('ssp.customized.class.php');
echo json_encode(
SSP::simple( $_POST, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraWhere)
);
?>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>Full name</th>
<th>Class room</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>Full name</th>
<th>Class room</th>
</tr>
</tfoot>
</table>
<script src="init-example-table.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment