【发布时间】:2017-04-19 18:32:13
【问题描述】:
如何在 codeigniter 中对我的 ajax 结果行进行分页。我想显示我的 ajax 结果,这将是 10-20 行,每页 4 或 5 行。帮我解决。这不是 Ajax 分页,而是在 ajax 调用中进行 ajax 分页。谢谢
这是我的视图文件:
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.12/datatables.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"> </script>
<script>
$(document).ready(function(){
$("#getreport").click(function(){
var fromdate = $('#date1').val();
var todate = $('#date2').val();
$("#header").css("visibility", "visible");
// $("#bodycontent").empty();
// $("#bodycontent").html('<div id="subcontent"></div>');
data =
{
"from" : fromdate,
"to" : todate
}
$.post('<?=site_url("Report/managecustomers_report"); ?>', data ,function (data) {
$('#datatable').dataTable({
data : data
// columns : [
// { 'data' : 'picture'},
// { 'data' : 'customername'},
// { 'data' : 'contactperson'},
// { 'data' : 'mobilenumber'},
// { 'data' : 'phone'},
// { 'data' : 'email'},
// ]
});
});
});
});
</script>
<div class="table-responsive">
<table class="table allcp-form theme-warning fs13">
<thead>
<tr class="bg-light">
<th class="">Image</th>
<th class="">Customer Name</th>
<th class="">Contact Person</th>
<th class="">Mobile Number</th>
<th class="">Phone</th>
<th class="">Email</th>
</tr>
</thead>
</table>
</div>
我的控制器:
public function managecustomers_report()
{
$query = $this->Reportmodel->customerreport_select($this->input->post('from'),$this->input->post('to'));
$data = $query['records'];
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($data));
return $data;
}
我的模型文件:
public function customerreport_select($date1,$date2)
{
$this->db->where('date >=', $date1);
$this->db->where('date <=', $date2);
$query=$this->db->get('customers');
$row = $query->result();
print_r($row);
return array(
'records' => $row,
'count' => count($row));
}
【问题讨论】:
-
你应该缩进你的代码...
-
这不是一个好习惯,但是您可以在控制器本身中创建 html,然后在您的 ajax 请求中返回该 html。然后使用 jQuery 替换 html。
标签: jquery ajax codeigniter pagination