Я выбрал данные из базы данных с передачей generator_id
в качестве параметра, я выполнил запрос в Модель & Контроллер , но как передать generator_id
в jquery извлекать данные в таблицу данных на основе id
. кто-нибудь может мне помочь?
Пример:
При прохождении generator id 1
, в таблицу данных должны быть извлечены детали генератора идентификатора 1.
Большое спасибо
Моя модель:
public function getGeneratorRAReport($param,$generator_id){
$arOrder = array('','RA_number');
$this->db->where("RA_status",1);
$this->db->where("generator_id",$generator_id);
if ($param['start'] != 'false' and $param['length'] != 'false') {
$this->db->limit($param['length'],$param['start']);
}
$this->db->select('*,DATE_FORMAT(RA_start_date,\'%d-%m-%Y\') as RA_start_date,DATE_FORMAT(RA_end_date,\'%d-%m-%Y\') as RA_end_date');
$this->db->from('rental_agreement');
$this->db->join('customer','customer_id = customer_id_fk');
$this->db->join('generators','generator_id = generator_id_fk');
$this->db->join('rental_plan','rental_plan_id = rental_plan_id_fk');
$this->db->order_by('RA_id', 'DESC');
$query = $this->db->get();
$data['data'] = $query->result();
$data['recordsTotal'] = $this->getGeneratorRAReportTotalCount($param,$generator_id);
$data['recordsFiltered'] = $this->getGeneratorRAReportTotalCount($param,$generator_id);
return $data;
}
public function getGeneratorRAReportTotalCount($param,$generator_id){
$this->db->where("RA_status",1);
$this->db->where("generator_id",$generator_id);
if ($param['start'] != 'false' and $param['length'] != 'false') {
$this->db->limit($param['length'],$param['start']);
}
$this->db->select('*');
$this->db->from('rental_agreement');
$this->db->join('customer','customer_id = customer_id_fk');
$this->db->join('generators','generator_id = generator_id_fk');
$this->db->join('rental_plan','rental_plan_id = rental_plan_id_fk');
$this->db->order_by('RA_id', 'DESC');
$query = $this->db->get();
return $query->num_rows();
}
Мой контроллер: -
public function index()
{
$template['body'] = 'Generators/Generator_RAReport';
$template['script'] = 'Generators/Generator_RAReport_script';
$this->load->view('template', $template);
}
public function get($generator_id){
$this->load->model('Generator_model');
$param['draw'] = (isset($_REQUEST['draw']))?$_REQUEST['draw']:'';
$param['length'] =(isset($_REQUEST['length']))?$_REQUEST['length']:'10';
$param['start'] = (isset($_REQUEST['start']))?$_REQUEST['start']:'0';
$param['order'] = (isset($_REQUEST['order'][0]['column']))?$_REQUEST['order'][0]['column']:'';
$param['dir'] = (isset($_REQUEST['order'][0]['dir']))?$_REQUEST['order'][0]['dir']:'';
$param['searchValue'] =(isset($_REQUEST['search']['value']))?$_REQUEST['search']['value']:'';
$data = $this->Generator_model->getGeneratorRAReport($param,$generator_id);
$json_data = json_encode($data);
echo $json_data;
}
Вид: -
<div class="box-body table-responsive">
<table id="RA_details_table" class="table table-bordered table-striped">
<thead>
<tr>
<th>Sl No.</th>
<th>RA number</th>
<th>RA type</th>
<th>Customer</th>
<th>RA start date</th>
<th>RA end date</th>
<th>Description</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<!-- /.box-body -->
скрипт: -
$(function () {
var RA_type = {'I':'Inside','O':'Outside'};
$table = $('#RA_details_table').DataTable( {
"searching": false,
"processing": true,
"serverSide": true,
"bDestroy" : true,
dom: 'lBfrtip',
buttons: [
],
"ajax": {
"url": "<?php echo base_url();?>index.php/Generator_RAReport/get/",
"type": "POST",
"data" : function (d) {
}
},
"createdRow": function ( row, data, index ) {
$table.column(0).nodes().each(function(node,index,dt){
$table.cell(node).data(index+1);
});
$('td',row).eq(2).html(RA_type[data['RA_type']]);
},
"columns": [
{ "data": "RA_id", "orderable": false },
{ "data": "RA_number", "orderable": false },
{ "data": "RA_type", "orderable": false },
{ "data": "customer_name", "orderable": false },
{ "data": "RA_start_date", "orderable": false },
{ "data": "RA_end_date", "orderable": false },
{ "data": "RA_description", "orderable": false }
]
} );