updating rows without refreshing

updating rows without refreshing

bluebaronbluebaron Posts: 33Questions: 0Answers: 0
edited May 2012 in DataTables 1.9
I've been trying any way I can to update rows in the table without refreshing.
The problem with this code is that rows in later pages will not be matched because they are not visible. It will, therefore, add a row to the datatable.
I have to think there's an easier way to update rows by ids.
I was thinking I would cycle through the array from getData, but how would I update those rows once I matched them by the id?

[code]
host_list_table = $('#host_list_table').dataTable({
"sScrollY": "15em",
"sScrollX": "45em",
"sPaginationType": "full_numbers",
"bJQueryUI": true,
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"iDisplayLength": 25,
"fnRowCallback": function (nRow, aData) { $(nRow).attr("id", "host_row_" + aData[4]); },
"aoColumns": [null, null, null, null, {"bVisible": false}]

});


$.getJSON('/get_host_list_array?host_list_id=' + host_list_id, function (data) {
if(!data.success) {
$('#error_hosts').text(data.message).show();
return;
}
$('#error_hosts').text('').hide();
//host_list_table.fnClearTable(false);

for(var x = 0; x < data.hosts.length; ++x)
{
var adata = host_list_table.getData();


var row = $('#host_row_' + data.hosts[x][4]);

if(row.length == 0) {
host_list_table.fnAddData(data.hosts[x]);
continue;
}

var row_id = host_list_table.fnGetPosition($(row)[0]);
host_list_table.fnUpdate(data.hosts[x], row_id);
}

//host_list_table.fnAddData(data.hosts);
//host_list_table.fnUpdate(data.hosts);

if(auto_resolve) AutoResolve();

if(resolve_running)
setTimeout("AutoResolve(false)", 1000);
});
[/code]

Replies

  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    edited May 2012
    In case anyone's curious, here's json data:

    [code]
    [
    {
    "0":"192.168.73.11",
    "1":"",
    "2":"",
    "3":"",
    "4":"2710"
    },
    {
    "0":"192.168.73.12",
    "1":"",
    "2":"",
    "3":"",
    "4":"2711"
    },
    ...
    [/code]
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    bump
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    please see the reference pages. both functions fnAddData and fnUpdate allow you to pass a boolean value telling it to refresh or not (default is 'true')

    [code]
    host_list_table.fnAddData(data.hosts[x], false);
    [/code]
  • bluebaronbluebaron Posts: 33Questions: 0Answers: 0
    If it doesn't refresh, will it still update the data in the table? I need it to update the visual data but not refresh the entire table.
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    I think what fbas is saying is that you want to make an Ajax call to get your latest data and then use fnUpdate to put that latest data into the table.

    Allan
This discussion has been closed.