我正在dataTables
上的codeigniter
项目的server-side
中使用MSSQL Database
处理item 11 - 20
。几个月前,我已经在其他项目中使用了该插件,而没有类似的问题。每次我转到表格的另一页时,数据都会显示接下来的10条记录(11 - 20
)。而是将下一个记录1 - 10 records
附加在第一个MySQL database
下。以下代码正在使用Limit
处理其他项目。我在想这是否是因为Top
的问题是pagination
而不是var table = $('#impDT').DataTable({
"language": {
"processing": "<i class='fa fa-circle-o-notch fa-spin fa-3x fa-fw' style='font-size:2em'></i>"
},
"aLengthMenu": [[10, 25, 50], [10, 25, 50]],
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:'impEntryDT',
type:"POST"
},
"columnDefs":[
{
"targets":[5],
"orderable":false,
},
],
dom:'lBfrtip',
buttons: [
{
extend: 'excelHtml5',
text: '<i class="fa fa-file-excel-o" aria-hidden="true"></i> Excel',
className: 'export-btn',
titleAttr: 'Excel',
title: 'Excel- Formal Entry'
},
{
extend: 'csvHtml5',
text: '<i class="fa fa-file-text-o" aria-hidden="true"></i> CSV',
className: 'export-btn',
titleAttr: 'CSV',
title: 'CSV- Formal Entry'
},
{
extend: 'pdfHtml5',
text: '<i class="fa fa-file-pdf-o" aria-hidden="true"></i> PDF',
className: 'export-btn',
titleAttr: 'PDF',
title: 'PDF - Formal Entry'
},
{
text: '<i class="fa fa-refresh" aria-hidden="true"></i>',
className: 'refresh-btn',
action: function ( e, dt, node, config ){
table.clear().draw();
table.ajax.reload();
}
}
]
});
?
这是我的view.php代码
public function get_formal_list(){
$entry = 'formal';
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $this->Formal_m->get_all_data($entry),
"recordsFiltered" => $this->Formal_m->get_filtered_data($entry),
"data" => $this->Formal_m->make_datatables($entry)
);
echo json_encode($output);
}
Controller.php
public function make_datatables($entry){
$COMINS2 = $this->load->database('comins2', TRUE);
if($entry == 'formal'){
$COMINS2->select('*')
->from('TBLIMPAPL_MASTER');
if(isset($_POST["order"])) {
$COMINS2->order_by($this->order_column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}else{
$COMINS2->order_by('ApplNo', 'DESC');
}
if($_POST["length"] != -1){
$COMINS2->limit($_POST['length'], $_POST['start']);
}
$result = $COMINS2->get()->result();
return $this->formal_domain_logic($result, $entry);
}
}
public function formal_domain_logic($fetch_data, $entry){
$data = array();
foreach($fetch_data as $row){
$sub_array = array();
$sub_array[] = "<a onclick='edit_view_formal(".$row->ApplNo."); ' href='#edit_informal' class='edit_informal'>
<font color='blue'>".$row->ApplNo."<font>
<input type='hidden' id='appnum".$row->ApplNo."' value='".$row->ApplNo."'</a>";
$sub_array[] = $row->MDec;
$sub_array[] = $row->ConTIN;
$sub_array[] = $row->ConName;
$sub_array[] = $row->Stat;
$sub_array[] = $row->CreationDate;
$data[] = $sub_array;
}
return $data;
}
public function get_filtered_data($entry){
$COMINS2 = $this->load->database('comins2', TRUE);
if($entry == 'formal'){
$COMINS2->select('*')
->from('TBLIMPAPL_MASTER');
}
if(isset($_POST["order"])) {
$COMINS2->order_by($this->order_column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}else{
$COMINS2->order_by('ApplNo', 'DESC');
}
return $result = $COMINS2->get()->num_rows();
}
}
public function get_all_data($entry)
{
$COMINS2 = $this->load->database('comins2', TRUE);
if($entry == 'formal'){
$COMINS2->select('*')
->from('TBLIMPAPL_MASTER');
return $COMINS2->count_all_results();
}
}
Model.php
var changedemployeesarray = [
{
"empId": "1126",
"name": "sam"
},
{
"empId": "1128",
"name": "mike"
},
{
"empId": "1136",
"name": "steve"
}
]
var allemployees = [
{
"empFullName": "sam Raj",
"empInfo": {
"empSeq": "1126",
"createDate": "2018-10-17"
},
"modfiedDate": "2018-10-24"
},
{
"empFullName": "mike",
"empInfo": {
"empSeq": "1128",
"createDate": "2018-10-17"
},
"modfiedDate": "2018-10-24"
},
{
"empFullName": "steve",
"empInfo": {
"empSeq": "1134",
"createDate": "2018-10-17"
},
"modfiedDate": "2018-10-24"
}
]
var updatearray = [];
var createarray = [];
updatearray = changedemployeesarray.filter(a=> allemployees.some(b=> b.empInfo.empSeq === a.empId));
createarray = changedemployeesarray.filter(a=> !allemployees.some(b=> b.empInfo.empSeq === a.empId));
console.log("updatearray",updatearray)
console.log("createarray",createarray)