updating rows without refreshing
updating rows without refreshing
bluebaron
Posts: 33Questions: 0Answers: 0
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]
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]
This discussion has been closed.
Replies
[code]
[
{
"0":"192.168.73.11",
"1":"",
"2":"",
"3":"",
"4":"2710"
},
{
"0":"192.168.73.12",
"1":"",
"2":"",
"3":"",
"4":"2711"
},
...
[/code]
[code]
host_list_table.fnAddData(data.hosts[x], false);
[/code]
Allan