我做了一个分页,从视图中传递data
到ajax
。如果它跳过$config['uri_segemnt']
。在这里,我手动设置总行数和per page
。
该函数创建所有html tags
和pagination tags
并将它们附加到view
。它正在工作,但分页每次只显示三个数字。似乎是分页而不是计算total row count
,我该如何解决这个问题?
这是我的功能和观点。
PHP控制器功能
public function getVoucherajax() {
if (!empty($_POST)) {
$offset = $_POST['limit'];
$selecttedList = $_POST['listID'];
} else {
$offset = 0;
}
$count = $this->getTotalOCount($selecttedList);
$voucherCount = $count[0]['vcount'];
//$limit = perpage
$allvouchers = $this->voucher_model->getallvouchers($this->perPage(), $offset, $selecttedList);
$config = array();
$config['total_rows'] = 56;
$config['per_page'] = 10;
////bootstrap config for pagination
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
echo 'Row Count -'.' '.$config['total_rows'];
$links = $this->pagination->create_links();
// print_r($allvouchers);
?>
<div class="col-sm-12">
<table class="table table-hover">
<thead>
<tr>
<th width="50">id</th>
<th width="150">Created</th>
<th width="150">Valid From</th>
<th width="150">Valid To</th>
<th width="100">Type</th>
<th width="100">State</th>
</tr>
</thead>
<tbody>
<?php
foreach ($allvouchers['allVouchers'] as $rows) {
?>
<tr>
<td><?php echo $rows['id'] ?></td>
<td><?php echo $rows['created'] ?></td>
<td><?php echo $rows['validfrom'] ?></td>
<td><?php echo $rows['validto'] ?></td>
<td><?php echo $rows['type'] ?></td>
<td><?php echo $rows['state'] ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php echo $links; ?>
</div>
<?php
}
视图
<script>
$(function () {
loadList()
loadVoucher()
pagination()
function loadList() {
$.ajax({
method: "POST",
url: "<?php echo base_url(); ?>login/loadListsAjax",
}).done(function ($data) {
$("#list").html($data);
});
}
function loadVoucher() {
$("#list").change(function () {
var listID = $(this).val();
$.ajax({
method: "POST",
url: "<?php echo base_url(); ?>login/getVoucherajax",
data: {limit: 0,listID: listID}
}).done(function($data){
$("#contents").html($data);
});
});
}
function pagination(){
$(document).on("click",".pagination li a",function(event) {
event.preventDefault();
// alert('sddsd');
var segment = $(this).attr("data-ci-pagination-page");
if(!segment){
segment = 0;
}
var list = $("#list").val();
// alert(list);
//
$.ajax({
method: "POST",
url: "<?php echo base_url(); ?>login/getVoucherajax",
data: {limit: segment,listID: list}
}).done(function($data){
$("#contents").html($data);
});
});
}
});
</script>
<div class="col-sm-9">
<div class="row">
<div class="col-sm-3">
<select id="list" class="form-control">
</select>
</div>
</div>
<div id="contents" class="row" style="padding-top: 100px;">
</div>
在图片顶部显示query
和total row count.