General Dynamic Data From Server (PHP)
General Dynamic Data From Server (PHP)
Hello,
i have a problem. I want load data from php / mysql. Ok here is my Code:
datatable.js:
[code]
$.ajax( {
type: "POST",
url: "loaddata.php",
data: { id: $("[id=example]").attr('name') },
success: function (dataStr) {
var data = eval( '('+dataStr+')' );
var oTable = $('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "datatable.php",
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "table", "value": $("#example").attr('name') } );
},
"aoColumnDefs": data.aoColumnDefs,
"aaSorting": data.aasorting
}).columnFilter({ aoColumns: data.aoColumns });
}
} );
[/code]
loaddata.php:
[code]
$output = array(
"aaSort" => array(),
"aoColumns" => array(),
"aoColumnDefs" => array()
);
$row[] = '{ "bSortable": false, "aTargets": [ 0 ] }';
$output['aoColumnDefs'][] = $row;
echo json_encode( $output );
[/code]
The php File is my problem. I dont know, what can i do that this go on.
Please forgive my english!
Bixas15
i have a problem. I want load data from php / mysql. Ok here is my Code:
datatable.js:
[code]
$.ajax( {
type: "POST",
url: "loaddata.php",
data: { id: $("[id=example]").attr('name') },
success: function (dataStr) {
var data = eval( '('+dataStr+')' );
var oTable = $('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "datatable.php",
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "table", "value": $("#example").attr('name') } );
},
"aoColumnDefs": data.aoColumnDefs,
"aaSorting": data.aasorting
}).columnFilter({ aoColumns: data.aoColumns });
}
} );
[/code]
loaddata.php:
[code]
$output = array(
"aaSort" => array(),
"aoColumns" => array(),
"aoColumnDefs" => array()
);
$row[] = '{ "bSortable": false, "aTargets": [ 0 ] }';
$output['aoColumnDefs'][] = $row;
echo json_encode( $output );
[/code]
The php File is my problem. I dont know, what can i do that this go on.
Please forgive my english!
Bixas15
This discussion has been closed.
Replies
I don't think you want server-side processing here. If you do, then the PHP is massively incomplete :-). See:
http://datatables.net/development/server-side/php_mysql
http://datatables.net/usage/server-side
What does your JSON return from the server look like? You want something like this (scroll down to see the response from the server): http://datatables.net/release-datatables/examples/data_sources/ajax.html
Allan
Thanks for the info.
Server side processing works for me.
What I want is that I have the settings (for example: aoColumndef, aasort, etc) loaded by PHP.
Currently, I get that back from json:
["{' bSortable ": false," aTargets': [0]}"]
Unfortunately, this is false.
Unfortunately, I do not know how to edit my array that comes out at the right. Can anyone say what my look and my JS to make it work with PHP?
Allan