DataTables with Node.js and socket.io
DataTables with Node.js and socket.io
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]
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]
This discussion has been closed.
Replies
Allan
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]