How can I highlight new loaded record after realoding datatable using ajax.reload() method?

How can I highlight new loaded record after realoding datatable using ajax.reload() method?

shomonrobieshomonrobie Posts: 1Questions: 1Answers: 0

I can reload DataTable using ajax and timer. Now, I want to highlight the new found record on the datatable, is it posible?

window.setInterval(function(){
/// call your function here
$('#notification').DataTable().ajax.reload(function (json) {

            if(json=="")
                {
                 $('#newUpdate').append('<div style="color:red">No Updates available</div>'); 
                //console.log ('no update');
                }
            else
                {
                                       'I WANT TO GET NEWLY FOUND RECORDS 
                                       ' AND HIGHLIGHT THOSE  NEWLY FOUND RECORDS  IN DATA TABLE

                }
            });

        }, 3000);

Thank you for your help in advance.

Answers

  • allanallan Posts: 61,450Questions: 1Answers: 10,055 Site admin

    The problem with ajax.reload() is that it is basically a short cut for:

    $.ajax( {
      url: ...,
      success: function (json) {
        table.clear();
        table.rows.add(json)
      }
    } );
    

    So really every row is new since all have been deleted and then added.

    What you really want is an update on the rows which are different. DataTables' API doesn't provide a method for that - you'd need to check the newly loaded data against the existing rows to find the rows which are updated, added and removed.

    Allan

This discussion has been closed.