我在一个选项卡中有一个数据表,该表是从索引方法上的控制器发送的数据中加载的。
$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'); } }); });