Update aaData with keeping Sorting and Searching, without destroying + re-creating... How?

Update aaData with keeping Sorting and Searching, without destroying + re-creating... How?

datatableryopmailcomdatatableryopmailcom Posts: 9Questions: 3Answers: 0

Greetings!

I'm using ajax's jQuery's $.get() - to fetch aaData and Header of a table.

Thereafter, simple creating of a table by such way:

var j = JSON.parse( data );

$('#dt_name').dataTable( {
  "aaData":  j['method']['aaData'],
  "aoColumns": j['method']['header'],
 } );

Everything fine.

Now, I'm looking for a neat way to update aaData of a table without full and complete reloading of a page or even div tag.

Is there?

For example, I can see very dirty way
to brute all of aaData of a table and row by row compare it with Updates.
If any changes,
then
replace by cell() method aaData in table.
go_to next cell...

Is it correct way?

I'm asking, because methinks that it is too ugly and hard for resources of a client-browser way.

For example, such method like:

dataTable.updateaaData( newaaData ); // shall replace every new datas and keep sorting + searching. Howevery, I can't find one.

Cheers!

Answers

  • datatableryopmailcomdatatableryopmailcom Posts: 9Questions: 3Answers: 0

    Solved.

    I've used such construction:

         // on update 
         var dt = $('#dt_name').dataTable();
         dt.fnClearTable( false );
         dt.fnAddData( j['method']['aaData'] );
    
  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    That's the way to do it :-). Or using the modern API rather than the legacy one, use clear() and rows.add().

    Allan

This discussion has been closed.