I'm trying to implement https://www.datatables.net/examples/data_sources/server_side.html into Typo3 (6.2LTS) with a flexible content element and templavoila. The result is a functioning but empty (No data available in table) table at the moment. I'm using the following php script:
<?php
class custom_datatable {
var $datatable; // reference to the calling object.
function custom_table1($columns,$conf)
{
global $TSFE;
$TSFE->set_no_cache();
//do whatever you want here
//db verbindung
mysql_connect("my_host", "my_user", "my_password");
mysql_select_db("my_database");
/*
* 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 = 'my_table';
// 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' => 'Field1', 'dt' => 0 ),
array( 'db' => 'Field2', 'dt' => 1 ),
array( 'db' => 'Field3', 'dt' => 2 ),
array( 'db' => 'Field4', 'dt' => 3 ),
array( 'db' => 'Field5', 'dt' => 4 ),
array( 'db' => 'Field6', 'dt' => 5 )
);
return $columns;
}
}
?>
And get the following result in the source code:
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Field1</th>
<th>Field2</th>
<th>Field3</th>
<th>Field4</th>
<th>Field5</th>
<th>Field6</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Field1</th>
<th>Field2</th>
<th>Field3</th>
<th>Field4</th>
<th>Field5</th>
<th>Field6</th>
</tr>
</tfoot>
</table>
<script type="text/javascript">
$(document).ready(function() {
$('#example').dataTable( {
"processing": true,
"serverSide": true,
"ajax": "Array"
} );
} );
</script>
What am I doing wrong or is missing?
in order for the server side processing to work, you must pass the right data format into it,
then you should also check the ssp class found on github for the server side-processing query https://github.com/DataTables/DataTables/blob/master/examples/server_side/scripts/ssp.class.php
for additional information please visit http://legacy.datatables.net/usage/server-side
You should use it like this one:
in your datatables initialization
PHP FIle:
note: this is a working example, I am using code igniter as the base framwork,and MySQL as the database, if you want to convert it to PHP, just replace the code igniter functions with the standard php $GET methods
you will need to $GET the following from the client to make it work.
and this is where the data is processed to be passed back to client page