2016-08-12 53 views
0

我應該在數據表中重新載入數據使用功能刪除項目 我把函數中的數據表中不同的文件後: 這是我的刪除功能:從另一個JS另一個函數重載dataTable的AJAX源文件

function removeFunction(table,id) { 
    var txt= $('.titleSup').text(); 
    var txt2= $('.textSup').text(); 
    swal({ 
     title:"Delete", 
     text: txt, 
     type: "warning", 
     showCancelButton: true, 
     confirmButtonColor: "#DD6B55", 
     confirmButtonText: "Yes !", 
     cancelButtonText: "No, cancel", 
     closeOnConfirm: false, closeOnCancel: false 
    }, function(isConfirm){ 
     if (isConfirm) { 
      $.ajax({ 
       url: "ajax/delete.php?for="+table+"&id="+id, 
       success : function(data){ 
        if(data == 'ok'){ 
         swal({ 
          title:"Delete", 
          text: txt2, 
          type: "success",  
          confirmButtonColor: "#AEDEF4", 
          confirmButtonText: "Ok", 
          closeOnConfirm: true, 
         }, function(isConfirm){ 
          //reload here 
         }); 
        }else{ 
         swal("Error, try again", "", "error"); 
        } 
        } 
      }); // end ajax call 

     } else {  
      swal("Cancel", "", "error"); 
     } 
    }); 
} 

,這是我的數據表的文件:

var TableData = function() { 
    //function to initiate DataTable 
    //DataTable is a highly flexible tool, based upon the foundations of progressive enhancement, 
    //which will add advanced interaction controls to any HTML table 
    //For more information, please visit https://datatables.net/ 
    var runDataTable = function() { 
     var oTable = $('#sample_1').dataTable({ 
      "sAjaxSource": 'ajax/get_companys.php', 
      "aoColumns": [ 
       { "mData": "register_no" }, 
       { "mData": "name" }, 
       { "mData": "email" }, 
       { "mData": "phone" }, 
       { "mData": "fax" }, 
       { "mData": "nbr_customer" }, 
       { "mData": "nbr_user" }, 
       { "mData": "created" } 

      ], 
      "aoColumnDefs": [{ 
       "aTargets": [0] 
      }], 
      "oLanguage": { 
       "sLengthMenu": "Show _MENU_ Rows", 
       "sSearch": "", 
       "oPaginate": { 
        "sPrevious": "", 
        "sNext": "" 
       } 
      }, 
      "aaSorting": [ 
       [2, 'desc'] 
      ], 
      "aLengthMenu": [ 
       [5, 10, 15, 20, -1], 
       [5, 10, 15, 20, "All"] // change per page values here 
      ], 
      // set the initial value 
      "iDisplayLength": 10, 
     }); 
    }; 
    return { 
     //main function to initiate template pages 
     init: function() { 
      runDataTable(); 
     } 
    }; 
}(); 

我如何可以訪問到數據表元素和relaoad他的數據源在RemoveFunction Ajax調用成功功能,謝謝。

回答

0

你只需要使用$("#sample_1").dataTable().draw();

相關問題