Reload table without refresh with Ajax jQuery

Asked

Viewed 851 times

1

I have a table that has the option to update records, but need that when changing a record it is changed dynamically in the table without the need for refresh.. already working the part of the server it already changes the data and tals.. however I need to refresh the page to see the change made.. I have the following JS:

if(e.update){
    $('#insert_form').each(function(){
         $('.alert').removeClass('alert-danger').addClass('alert-success');
                this.reset();
         });

    // Aqui eu preciso recarregar a tabela..
    $('#employee_table') // Refresh!

}

is inside a request, and if the return is update it var execute the function inside..

1 answer

1

If you choose to rebuild the table, you could remove the content from tbody and render again with the return of jQuery ajax. Something like:

success: function (result) {     
    $('tbody').empty();
    result.forEach(function(item){
       $('tbody').append('<tr><th>'+item.chave+'</th></tr>');
    })
})
  • exact, however there is no other way without needing to rebuild the same?

  • Yes @Drik, have a unique identifier of the table row and change its properties with the return.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.