当我从下拉列表中选择全部以显示所有记录时,它显示错误的计数,例如:-(显示 288 个条目中的 1 到 293)
我很困惑下面是我的代码,请检查并告诉我解决方案
表格视图是:-
<table id="measuretable" class="table table-striped table-bordered" cellspacing="0"
width="100%">
<thead>
<tr>
<!-- <th width="5%">id</th> -->
<th>Measure</th>
<th>Full Name</th>
<th>Ready</th>
<th>Memo</th>
</tr>
<tr>
<!-- <th><input type="hidden" class="form-control column-search" data-column="0"></th> -->
<th><input type="text" class="form-control column-search" data-column="0"></th>
<th><input type="text" class="form-control column-search" data-column="1"></th>
<th><input type="hidden" class="form-control column-search" data-column="2"></th>
<th><input type="text" class="form-control column-search" data-column="3"></th>
</tr>
</thead>
<tbody></tbody>
</table>
脚本是:-
var table = $('#measuretable').DataTable({
"processing": true,
"serverSide": true,
"paging": true,
"orderable": true,
"ajax": {
"url": "<?php echo base_url('user/getMeasuresData'); ?>",
"type": "GET"
},
"columns": [{
"data": "0"
},
{
"data": "1"
},
{
"data": "2"
},
{
"data": "3"
},
]
});
$('#measuretable tbody').on('click', 'tr', function() {
var row = table.row(this).data();
if (row) {
window.location.href = "<?php echo base_url('user/editMeasure/'); ?>" + row.DT_RowId;
}
});
$('#measuretable tbody').hover(function() {
$(this).css('cursor', 'pointer');
});
$('.column-search').on('keyup', function() {
var column = table.column($(this).data('column'));
var searchTerm = $(this).val().trim();
if (searchTerm === '') {
column.search('').draw();
} else {
column.search(searchTerm).draw();
}
});
$('#measuretable tbody').on('click', '.row-clickable', function() {
var id = $(this).find('td:first-child').text();
window.location.href = '<?php echo base_url('user/editMeasure/'); ?>' + id;
});
控制器功能是:-
public function getMeasuresData()
{
$data = $this->measure->getMeasureList($this->input->get());
$rowCount = $data['recordsTotal'];
$output = array(
"sEcho" => intval($this->input->get('sEcho')),
"iTotalRecords" => $rowCount,
"iTotalDisplayRecords" => $rowCount,
"aaData" => []
);
$i = $this->input->get('iDisplayStart') + 1;
foreach ($data['data'] as $val) {
$output['aaData'][] = array(
"DT_RowId" => $val['0'],
$val['0'],
$val['1'],
($val['2'] == 1 ? 'Yes' : 'No'),
$val['3'],
);
}
echo json_encode($output);
die;
}
模型函数是:-
public function getMeasureList($params = array())
{
$start = isset($params['start']) ? intval($params['start']) : 0;
$limit = isset($params['length']) ? intval($params['length']) : 10;
$columns = array(
0 => 'id',
1 => 'short_name',
2 => 'full_name',
3 => 'ready',
4 => 'memo'
);
$order_by = "id";
$dir = 'DESC';
$order = 'id';
if (isset($params['start'])) {
$start = intval($params['start']);
}
if (isset($params['length'])) {
$limit = intval($params['length']);
}
if (isset($params['order'][0]['column'])) {
$index = $params['order'][0]['column'];
$order = $params['order'][0]['dir'] === 'asc' ? 'asc' : 'desc';
$order_by = $columns[$index];
}
$this->db->select('m.id,m.short_name,m.full_name,m.ready,p.memo')
->join('publication_assignments p', 'p.measure_id = m.id', 'left')
->distinct('m.id');
if ($limit != -1) {
$this->db->limit($limit, $start);
}
$this->db->order_by($order_by, $dir);
$result = $this->db->get('measures m')->result_array();
$totalRecords = $this->db->select('count(*) as allcount')->from('measures')->count_all_results();
$totalFiltered = $totalRecords;
foreach ($params['columns'] as $key => $value) {
if (isset($value['search']['value']) && $value['search']['value'] != "") {
$words = $value['search']['value'];
$this->db->reset_query();
if($key == 0)
{
$this->db->select('m.id,m.short_name,m.full_name,m.ready,p.memo')
->join('publication_assignments p', 'p.measure_id = m.id', 'left')
->distinct('m.id')
->like('m.short_name', $words);
$result = $this->db->get('measures m')->result_array();
}
if($key == 1)
{
$this->db->select('m.id,m.short_name,m.full_name,m.ready,p.memo')
->join('publication_assignments p', 'p.measure_id = m.id', 'left')
->distinct('m.id')
->like('m.full_name', $words);
$result = $this->db->get('measures m')->result_array();
}
if($key == 3)
{
$this->db->select('m.id,m.short_name,m.full_name,m.ready,p.memo')
->join('publication_assignments p', 'p.measure_id = m.id', 'left')
->distinct('m.id')
->like('p.memo', $words);
$result = $this->db->get('measures m')->result_array();
}
}
}
$data = array();
foreach ($result as $row) {
$nestedData = array();
// $nestedData[] = $row["id"];
$nestedData[] = $row["short_name"];
$nestedData[] = $row["full_name"];
$nestedData[] = $row["ready"];
$nestedData[] = $row["memo"];
$data[] = $nestedData;
}
$json_data = array(
"recordsTotal" => intval($totalRecords),
"recordsFiltered" => intval($totalFiltered),
"data" => $data
);
return $json_data;
}
我试过了
if ($limit != -1) { $this->db->limit($limit, $start); }
但什么也没发生
谁能解释我哪里错了 提前致谢