Есть много доступных ресурсов. Для просмотра кода вызовите контроллер из функции jquery следующим образом.
<div class="table-responsive">
<table id="user_data" class="display table" style="width: 100%; cellspacing: 0;">
<thead>
<tr>
<th>Id</th>
<th>Product title</th>
<th>Product content</th>
<th>Product price</th>
<th>Product size</th>
<th>Product qty</th>
<th>Update</th>
<th>Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Id</th>
<th>Product title</th>
<th>Product content</th>
<th>Product price</th>
<th>Product size</th>
<th>Product qty</th>
<th>Update</th>
<th>Delete</th>
</tr>
</tfoot>
</table>
</div>
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
var dataTable = $('#user_data').DataTable({
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"<?php echo base_url() . 'admin_panel/fetch_product'; ?>",
type:"POST"
},
"columnDefs":[
{
"targets":[0, 3, 4],
"orderable":false,
},
],
});
</script>
Для стороны сервера вызовите функцию контроллера codeigniter, которая будет обрабатывать все данные из базы данных, используя модальную функцию, и отправлять ее на ajax вызов, который отобразит его в таблице:
public function fetch_product(){
$this->load->model("crud_model"); //This will load Modal into controller
$fetch_data = $this->crud_model->make_datatables("product",array("product_id", "product_title","product_desc","product_price","product_size","product_qty"),array("product_id", "product_title", null, null),"product_id","product_title","product_title"); // this will call modal function for fetching data
$data = array();
foreach($fetch_data as $row) // Loop over the data fetched and store them in array
{
$sub_array = array();
$sub_array[] = $row->product_id;
$sub_array[] = $row->product_title;
$sub_array[] = $row->product_desc;
$sub_array[] = $row->product_price;
$sub_array[] = $row->product_size;
$sub_array[] = $row->product_qty;
$sub_array[] = '<button type="button" name="update" data-id="'.$row->product_id.'" data-option=0 data-toggle="modal" data-target="#userModal" class="edit_post btn btn-warning btn-xs">Update</button>';
$sub_array[] = '<button type="button" name="delete" data-id="'.$row->product_id.'" data-toggle="modal" data-target="#myModal2" id="d_b" class="delete_post btn btn-danger btn-xs">Delete</button>';
$data[] = $sub_array;
}
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $this->crud_model->get_all_data("product"),
"recordsFiltered" => $this->crud_model->get_filtered_data("product",array("product_id", "product_title","product_desc","product_price","product_size","product_qty"),array("product_id", "product_title", null, null),"product_id","product_title","product_title"),
"data" => $data
);
echo json_encode($output);
}
Теперь при извлечении данных из модального режима модальный код будет выглядеть примерно так:
<?php
class Crud_model extends CI_Model
{
/* var $table = "banner";
var $select_column = array("banner_id", "banner_title", "banner_text", "banner_image");
var $order_column = array("banner_id", "banner_title", "banner_text", null, null);*/
function make_query($table,$select_column,$order_column,$where,$like,$or_like=false)
{
$this->db->select($select_column);
$this->db->from($table);
if(isset($_POST["search"]["value"]))
{
$this->db->like($like, $_POST["search"]["value"]);
$this->db->or_like($or_like, $_POST["search"]["value"]);
}
if(isset($_POST["order"]))
{
$this->db->order_by($order_column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else
{
$this->db->order_by($where, 'DESC');
}
}
function make_datatables($table,$select_column,$order_column,$where,$like,$or_like){
$this->make_query($table,$select_column,$order_column,$where,$like,$or_like);
if($_POST["length"] != -1)
{
$this->db->limit($_POST['length'], $_POST['start']);
}
$query = $this->db->get();
return $query->result();
}
function get_filtered_data($table,$select_column,$order_column,$where,$like,$or_like){
$this->make_query($table,$select_column,$order_column,$where,$like,$or_like);
$query = $this->db->get();
return $query->num_rows();
}
function get_all_data($table)
{
$this->db->select("*");
$this->db->from($table);
return $this->db->count_all_results();
}
/* function insert_crud($data)
{
$this->db->insert('users', $data);
}*/
Надеюсь, это поможет:)