DataTables logo DataTables

via Ad Packs
updating rows without refreshing
  • bluebaronbluebaron
    Posts: 33
    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?

        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);
        });
    
  • bluebaronbluebaron
    Posts: 33
    In case anyone's curious, here's json data:

    [
    {
      "0":"192.168.73.11",
      "1":"",
      "2":"",
      "3":"",
      "4":"2710"
    },
    {
      "0":"192.168.73.12",
      "1":"",
      "2":"",
      "3":"",
      "4":"2711"
    }, 
    ...
    
  • bluebaronbluebaron
    Posts: 33
    bump
  • fbasfbas
    Posts: 1,050
    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')

    host_list_table.fnAddData(data.hosts[x], false);
    
  • bluebaronbluebaron
    Posts: 33
    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: 15,556
    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.
← All Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.

In this Discussion