DataTables with Node.js and socket.io

DataTables with Node.js and socket.io

dflatleydflatley Posts: 2Questions: 0Answers: 0
edited February 2013 in General
Hi All,
I'm trying to get DataTables working with socket.io and refreshing every 500 milliseconds. I've read that others handled the same setup successfully, but I'm running into some weird issues. Right now, I have three columns and I'm seeing weird characters show up in one row for each, rather than the 26 rows I see coming back from the server in the console. The columns contain { " and s in each and I'm having a hard time trying to figure out what's going on there.

Originally, I had it running fine with the setInterval code I found on this forum, but ever since switching to socket.io, I'm pulling my hair out. Anyone with a similar set up have some suggestions?

Here's my debug info http://debug.datatables.net/inajeq

My code JavaScript looks like this.

[code]$(document).ready(function() {
var url = 'http://localhost:8081/refreshTable';
var refreshTable = io.connect(url);

var oTable;
oTable = $('#example').dataTable( {
"bJQueryUI": true,
"bServerSide": false,
"sAjaxSource": url
} );

refreshTable.on('field', function (data) {
console.log(data);

oTable.fnClearTable();
oTable.fnAddData(data);
oTable.fnReloadAjax();
//oTable.fnDraw();
});

} );[/code]

HTML table looks like this.

[code]


name
value
datetime




Loading...




[/code]

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Don't know I'm afraid. If you set your update rate to be slower, does it work reliably? Web Sockets are TCP so there shouldn't be any chance of data corruption on the wire.

    Allan
  • dflatleydflatley Posts: 2Questions: 0Answers: 0
    It seems I'm able to get data now using fnUpdate, but I'm not using it correctly. Right now, just to test I'm updating one column with the entire JSON string. So that's working fine, I'm just looking for more direction on how to update every row/column with $each.

    Those weird characters in each column were the first three from the JSON data string returned from the server {"s So instead of grabbing each value, name, and datetime, it was grabbing the first three characters of that string and putting them into each column in one row.

    [code]{"sEcho":1,"iTotalRecords":"26","iTotalDisplayRecords":"26","aaData":[{"value":"-4.134722","name":"[GLAD_DEMO]F8:0","datetime":"2/15/2013 8:06:42 PM"}, etc....
    [/code]

    Also, Allen thanks for this awesome tool and quick responses! I'm very impressed with Datatables and will be helping to support it going forward!

    Here's my JS code now:

    [code]refreshTable.on('field', function (data) {
    console.log(data);

    oTable.fnClearTable();
    oTable.fnAddData(data);
    oTable.fnUpdate( data, 0, 1 );// need to use fnUpdate on all columns/rows

    });[/code]
This discussion has been closed.