重新加载数据表而不用Ajax刷新 [英] Reloading a datatable without refreshing with ajax

查看:256
本文介绍了重新加载数据表而不用Ajax刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在选项卡中有一个数据表,该数据表是由控制器通过索引方法发送的数据加载的.

I have a datatable in a tab that is loaded from data sended by the controller on index method.

$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中加载了数据表

then I load the datatable in javascript when the page is loaded

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从控制器再次获取数据)?

I have a delete function too. How can I reload the data (using ajax for getting the data from controller again) without reloading the page?

推荐答案

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

      });

这篇关于重新加载数据表而不用Ajax刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆