Is there a reflow method for datatables?

Is there a reflow method for datatables?

GMorrisGMorris Posts: 4Questions: 1Answers: 0

I would need to call a reflow method after deleting some stuff from a table.

function doDelete(id)
{
    $.getJSON(window.location.origin+'/admin/reviews/delete/'+id,function(data){
        if(data.error == 0){
            $('tr[data-id="'+id+'"]').addClass('animated flash').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
                $('tr[data-id="'+id+'"]').hide().remove();
                alertHandle('Review #'+id+' was deleted','success');
            });
        }else{
            alertHandle(data.message,'error');
        }
    });
}

is there some function i can call on the datatables instance? i would like to redraw the datatable(ie update number of rows and pagination and such)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,858Questions: 1Answers: 10,344 Site admin

    If you want to remove rows from the table you need to use the API - specifically row().remove() or rows().remove(). Dropping them out using DOM methods doesn't work as DataTables doesn't know that you've deleted them using that method.

    If you need the animation, one option would be to call row().remove() in the callback once the row is hidden.

    Once all required rows have been removed, call draw() to redraw the table.

    Allan

  • GMorrisGMorris Posts: 4Questions: 1Answers: 0
    edited March 2015

    nm. i see that the highlighted segments refer to the section in the manual. thanks. bout to give it a test run. looks like it should work

  • GMorrisGMorris Posts: 4Questions: 1Answers: 0

    sweet, it works

  • allanallan Posts: 62,858Questions: 1Answers: 10,344 Site admin
    Answer ✓

    Excellent - thanks for the feedback :-)

    Allan

This discussion has been closed.