簡體   English   中英

重新加載數據表而不用Ajax刷新

[英]Reloading a datatable without refreshing with ajax

我在選項卡中有一個數據表,該數據表是從索引方法上的控制器發送的數據中加載的。

$data = array(
    'documents'      => $this->getDocuments(),
     //more stuff...
);

$this->load->view($this->config->item('groupViews') . 'example/example_edit_view', $data);

我有加載數據表的視圖

<div class="form-group col-md-12">
    <table
        id="t_documents"
        class="table table-striped table-bordered table-hover"
        cellspacing="0"
        width="100%">
     </table>
</div> 

然后在加載頁面時在javascript中加載數據表

var documentos = <?php echo json_encode($documents); ?>;
    if ( documentos !== null){
        var table = $('#t_documents').DataTable( {
            language: {
                "url": "<?=trad($this,'LANG_DATATABLES');?>"
     },
     data: documents,
     paging: true,
     ordering: true,
     pageLength: 10,
     columns: [
         { title: "" },    //Download button
         { title: "<?=trad($this,'FILE_NAME');?>" },
         { title: "<?=trad($this,'FILE_TYPE');?>" },
         { title: "" }     //Delete button
     ]
   });
}

我也有刪除功能。 我如何在不重新加載頁面的情況下重新加載數據(使用Ajax從控制器再次獲取數據)?

      var table=$('#tableid');
$('#tableid').on('click','thedeletebuton_id',function(event) {
      event.preventDefault();
      var id=$(this).data('id'); // pass the id to the controller to delete using ajax
       $.ajax({
           type: "POST",
           url: "<?php echo base_url('your controller'); ?>",
           data:  {id:id}, 
           success: function(data)
           {
            table.ajax.reload();   /// reloads the table
            alert('Deleted');
           }
       });

      });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM