server side datatable.no data is loading.
server side datatable.no data is loading.
gautambose
Posts: 8Questions: 3Answers: 0
I want to use serverside datatable. Here is the code.Where is the fault? No error is coming.only display header and footer.No Data is loading.
test.php
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Untitled 1</title>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" type="text/css">
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.12.3.min.js">
<script>
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "server-response.php",
},
"columns": [
{"data": "companyID"},
{"data": "cname"},
{"data": "caddress"},
{"data": "ccity"},
{"data": "cstate"},
],
} );
} );
</script>
</head>
<body>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>city</th>
<th>State</th>
</tr>
</thead>
<tfoot>
<tr>
<tr>
<th>Name</th>
<th>Address</th>
<th>city</th>
<th>State</th>
</tr>
</tfoot>
</table>
</body>
</html>
server-response.php
<?php
/*
* DataTables example server-side processing script.
*
* Please note that this script is intentionally extremely simply to show how
* server-side processing can be implemented, and probably shouldn't be used as
* the basis for a large complex system. It is suitable for simple use cases as
* for learning.
*
* See http://datatables.net/usage/server-side for full details on the server-
* side processing requirements of DataTables.
*
* @license MIT - http://datatables.net/license_mit
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
// DB table to use
$table = 'company';
// Table's primary key
$primaryKey = 'companyID';
// 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' => 'cname', 'dt' => 0 ),
array( 'db' => 'caddress', 'dt' => 1 ),
array( 'db' => 'ccity', 'dt' => 2 ),
array( 'db' => 'cstate', 'dt' => 3 ),
);
// SQL server connection information
$sql_details = array(
'user' => 'gb',
'pass' => '123',
'db' => 'test_database',
'host' => 'localhost'
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/
require( 'ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
This discussion has been closed.