在我的模型中,我加入了branch
from
数据之后却又加入了其他表to
,但是没有成功搜索并且其他数据搜索成功。
视图:
<section class="content">
<table id="example1" class='display dataTable'>
<thead class="bg-info">
<tr>
<th>Dispatch Challan No</th>
<th>Date</th>
<th>From</th>
<th>To</th>
<th>Lorry No.</th>
<th>Pan Card</th>
<th>Driver</th>
<th>Owner</th>
<th>Remark</th>
</tr>
</thead>
</table>
</section>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#example1').DataTable({
'processing': true,
'serverSide': true,
"bInfo": false,
'serverMethod': 'post',
'ajax': {
'url':'<?php echo base_url();?>booking/dispatch_challan/DispatchChallanController/getData'
},
'columns': [
{ data: 'disp_ch_no' },
{ data: 'disp_ch_date' },
{ data: 'from' },
{ data: 'to' },
{ data: 'vehicle' },
{ data: 'disp_ch_pan' },
{ data: 'disp_ch_driver' },
{ data: 'disp_ch_owner' },
{ data: 'disp_ch_remark' },
]
});
});
</script>
控制器:
public function getData()
{
// POST data
$postData = $this->input->post();
$data = $this->dispatchModel->viewData($postData);
echo json_encode($data);
}
型号:
function viewData($postData=null){
$response = array();
## Read value
$draw = $postData['draw'];
$start = $postData['start'];
$rowperpage = $postData['length']; // Rows display per page
$columnIndex = $postData['order'][0]['column']; // Column index
$columnName = $postData['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $postData['order'][0]['dir']; // asc or desc
$searchValue = $postData['search']['value']; // Search value
## Search
$searchQuery = "";
if($searchValue != ''){
$searchQuery = " (b.disp_ch_no like '%".$searchValue."%' or b.disp_ch_date like '%".$searchValue."%' or b.disp_ch_from like'%".$searchValue."%' or b.disp_ch_to like'%".$searchValue."%' or b.disp_ch_lorryno like'%".$searchValue."%' or b.disp_ch_pan like'%".$searchValue."%' or b.disp_ch_driver like'%".$searchValue."%' or b.disp_ch_owner like'%".$searchValue."%' or b.disp_ch_remark like'%".$searchValue."%') ";
}
if($searchValue != '')
$this->db->where($searchQuery);
$records = $this->db->get('dispatch_challan b')->result();
$this->db->select('bn.branch_name as from_branch_name,bn1.branch_name as to_branch_name,vn.vehicle_no as vehicle,b.*,vn.*,');
$this->db->from('dispatch_challan b');
$this->db->join('vehicle vn', 'b.disp_ch_lorryno=vn.vehicle_id','left');
$this->db->join('branch bn', 'b.disp_ch_from=bn.branch_id','left');
$this->db->join('branch bn1','b.disp_ch_to=bn1.branch_id','left');
$this->db->where('b.status','active');
if($searchValue != '')
$this->db->where($searchQuery);
$this->db->order_by($columnName, $columnSortOrder);
$this->db->limit($rowperpage, $start);
$records = $this->db->get()->result();
$data = array();
foreach($records as $record ){
$data[] = array(
"disp_ch_no" =>$record->disp_ch_no,
"disp_ch_date" =>$record->disp_ch_date,
"from" =>$record->from_branch_name,
"to" =>$record->to_branch_name,
"vehicle" =>$record->vehicle,
"disp_ch_pan" =>$record->disp_ch_pan,
"disp_ch_driver" =>$record->disp_ch_driver,
"disp_ch_owner" =>$record->disp_ch_owner,
"disp_ch_remark" =>$record->disp_ch_remark
);
}
## Response
$response = array(
"draw" => intval($draw),
"aaData" => $data
);
return $response;
}