刷新已更新表的一行

Refresh a row of updated table

本文关键字:一行 已更新 刷新      更新时间:2023-09-26

我有一个表,并且使用ajax更新了表的一行。当我单击save按钮时,我需要刷新表的修改行。到目前为止,我的代码是:

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
    ]
  });
}

它什么都不做!返回值和正在更新的数据表没问题,但刷新就不行了。顺便说一下,我正在使用CodeIgniter。有没有什么函数能让它更简洁?

用于刷新页面上的所有数据表:

$('#custtbl').each(function() {
    dataTable = $(this).dataTable();
    dataTable.fnDraw();
})
编辑:

$('#custtbl').dataTable().fnUpdate('Updated Value Here' , $('Dynamic Table ID Here')[0], 1 );