我有数据表,我正在尝试添加数据表,但是在搜索数据时它不起作用。 并记录重复多次。在每页排序中每页显示10条,但不起作用。 我正在使用引导程序4数据表CDN。
视图:
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/plugins/datatables/dataTables.bootstrap4.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/custom/css/custom_style.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/plugins/bootstrap/css/bootstrap.css">
<link rel=" https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
<link rel=" https://cdn.datatables.net/fixedcolumns/3.2.6/css/fixedColumns.bootstrap4.min.css">
<div class="content-wrapper">
<section class="content">
<div class="table-responsive">
<table id="example1" class="table table-bordered table-sm display dataTable" style=" overflow: auto;">
<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>
</div>
</section>
</div>
<script src="<?php echo base_url(); ?>assets/plugins/datatables/jquery.dataTables.js"></script>
<script src="<?php echo base_url(); ?>assets/plugins/datatables/dataTables.bootstrap4.js"></script>
<script href=" https://code.jquery.com/jquery-3.3.1.js"></script>
<script src=" <?php echo base_url(); ?>assets/plugins/datatables/jquery.dataTables.min.js"></script>
<script href=" https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
<script href=" https://cdn.datatables.net/fixedcolumns/3.2.6/js/dataTables.fixedColumns.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#example1').DataTable({
'processing': true,
'serverSide': true,
'serverMethod': 'post',
'ajax': {
'url':'<?php echo base_url();?>booking/dispatch_challan/DispatchChallanController/getData'
},
'columns': [
{ data: 'disp_ch_no' },
{ data: 'disp_ch_date' },
{ data: 'from_branch_name' },
{ data: 'to_branch_name' },
{ data: 'vehicle' },
{ data: 'disp_ch_pan' },
{ data: 'disp_ch_driver' },
{ data: 'disp_ch_owner' },
{ data: 'disp_ch_remark' },
]
});
});
</script>
</body>
</html>
控制器:
public function getData(){
$data = $this->dispatchModel->viewData();
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 = " (dispatch_challan_no like '%".$searchValue."%' or date like '%".$searchValue."%' or disp_ch_from like'%".$searchValue."%' or disp_ch_to like'%".$searchValue."%' or disp_ch_lorryno like'%".$searchValue."%' or pan_card like'%".$searchValue."%' or driver like'%".$searchValue."%' or Owner like'%".$searchValue."%' or remark like'%".$searchValue."%') ";
}
## Total number of records without filtering
$this->db->select('count(*) as allcount');
$records = $this->db->get('dispatch_challan')->result();
$totalRecords = $records[0]->allcount;
## Total number of record with filtering
$this->db->select('count(*) as allcount');
if($searchValue != '')
$this->db->where($searchQuery);
$records = $this->db->get('dispatch_challan')->result();
$totalRecordwithFilter = $records[0]->allcount;
## Fetch records
$this->db->select('b.status,b.disp_id,b.disp_ch_no,b.disp_ch_date,b.disp_ch_from,b.disp_ch_to,b.disp_ch_lorryno,b.disp_ch_pan,b.disp_ch_driver,b.disp_ch_owner,b.disp_ch_remark,vn.vehicle_no as vehicle,bn.branch_name as from_branch_name,bn1.branch_name as to_branch_name');
$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('dispatch_challan')->result();
$data = array();
foreach($records as $record ){
$data[] = array(
"disp_ch_no" =>$record->disp_ch_no,
"disp_ch_date" =>$record->disp_ch_date,
"from_branch_name" =>$record->from_branch_name,
"to_branch_name" =>$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),
"iTotalRecords" => $totalRecordwithFilter,
"iTotalDisplayRecords" => $totalRecords,
"aaData" => $data
);
return $response;
}
在上面的代码中,我正在联接表以获取名称。 我正在桌上获取数据,但搜索框无法正常工作。