views:

381

answers:

2

Hello Everyone , JQuery noob here ...

I have a Question regarding the DataTables Plugin.DataTables link.

The Plugin claims that:

A common use case for this is when you are displaying live information which could be periodically updated

Being a newbie, I cannot figure out how to initialize the Table using Ajax, so that the table updates itself dynamically if the server information is changed. ( That is when new information is added in the server, the change is displayed on the table real time)

P.S: I am using PHP as the server side script.

+2  A: 

This cannot happen automatically .. you will have to poll the server for changes .. either you or the plugin ..

You could utilize the fnReloadAjax method.. but you will have to manually (or though a time interval) call it ..

Gaby
A: 

You can use the fnUpdate or fnAddData functions and pass the information as an array, line by line.

var dataTable = $('#myTable').dataTable();
$.post('myServer.php', {update: 'table'}, function(data){
    var newTRNum = dataTable.getNodes().length + 1;
    $.each(data, function(i, tableRowInfo){
        dataTable.fnUpdate(tablerowInfo, newTrNum, 0);
        newTrNum++;
    });
}, 'json');

I haven't tested it, but likely something to that effect.

munch
Thank you, I will try this.
Ender Wiggin