javascript - Refresh a row of updated table
Get the solution ↓↓↓I have a table and with ajax, I updated a row of a table. I need to refresh the modified row of the table when I click on save button. So far my code is this:
function doedit()
{
var value = {
'c_firstname': $('#c_firstname').val(),
'c_lastname': $('#c_lastname').val(),
'c_gender': $("#c_gender option:selected").html(),
'c_age': $('#c_age').val(),
'c_job': $('#c_job').val(),
'c_address': $('#c_address').val(),
'c_phone': $('#c_phone').val(),
'c_mail': $('#c_mail').val(),
'c_state': $("#c_state option:selected").html(),
'c_intrest': $("#c_intrest option:selected").html(),
'c_added_info': $('#c_added_info').val()
};
$.ajax({
type: 'POST',
url: '<?php echo site_url('customers/updatecustomer'); ?>',
data: value,
success: function(resp){
$('#error').html(resp);
}
});
$('#custtbl').dataTable().fnDestroy();
$('#custtbl').dataTable({ // Cannot initialize it again error
"aoColumns": [
{ "bSortable": false },
null, null, null, null
]
});
}
It just do nothing! The returned value and the updating data table is fine but the refresh is not. I'm using CodeIgniter by the way. is there any function in it to do it in a short way?
Answer
Solution:
This is use to refresh all the data table that are on a page:
$('#custtbl').each(function() {
dataTable = $(this).dataTable();
dataTable.fnDraw();
})
Edit:
$('#custtbl').dataTable().fnUpdate('Updated Value Here' , $('Dynamic Table ID Here')[0], 1 );
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: npm err! code 1
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.