General Dynamic Data From Server (PHP)

General Dynamic Data From Server (PHP)

bixas15bixas15 Posts: 3Questions: 0Answers: 0
edited February 2012 in General
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

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > "bServerSide": true

    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
  • bixas15bixas15 Posts: 3Questions: 0Answers: 0
    edited February 2012
    Hello,
    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?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    You need to load your DataTables configuration by Ajax first, rather than after your initialise DataTables. Options such as aoColumns can't be changed after initialisation, so you would need to use $.getJSON or something like that to get your configuration and then initialise your table with those options.

    Allan
  • bixas15bixas15 Posts: 3Questions: 0Answers: 0
    edited February 2012
    Have you any Code?
This discussion has been closed.