单页中的多个分页



我为codeigniter在单个页面中创建了一个用于多个分页的脚本,但分页的链接都处于活动状态,假设第一个我在第三页上,第二个我在第一页上,但在第三个链接上都处于活动状态。请帮我解决这个问题。

这是我的代码,用于第一次分页

$config1 = array();
$config1["base_url"] = base_url();
$config1["total_rows"] = $this->admin_model->record_count($query1);
$config1["per_page"] = 30;
$config1["uri_segment"] = 4;
$config1['use_page_numbers'] = TRUE;
$choice = 3;
$config1["num_links"] = floor($choice);          
$config1['full_tag_open'] = '<ul class="pagination">';
$config1['full_tag_close'] = '</ul>';
$config1['first_link'] = 'First';
$config1['last_link'] = 'Last';
$config1['first_tag_open'] = '<li>';
$config1['first_tag_close'] = '</li>';
$config1['prev_link'] = '«';
$config1['prev_tag_open'] = '<li class="prev">';
$config1['prev_tag_close'] = '</li>';
$config1['next_link'] = '»';
$config1['next_tag_open'] = '<li>';
$config1['next_tag_close'] = '</li>';
$config1['last_tag_open'] = '<li>';
$config1['last_tag_close'] = '</li>';
$config1['cur_tag_open'] = '<li class="active"><a href="#">';
$config1['cur_tag_close'] = '</a></li>';
$config1['num_tag_open'] = '<li>';
$config1['num_tag_close'] = '</li>';
$config1['prefix'] = "/".$this->uri->segment(3)."/";
$config1['suffix'] = "";
$config1['first_url'] = base_url() ."/".$this->uri->segment(3)."/0/";
$this->pagination->initialize($config1);
$page = ($this->uri->segment(4)) ? (($this->uri->segment(4)*$config1["per_page"])-$config1["per_page"]) : 0;
$queryLimit =" LIMIT $page, {$config1["per_page"]}";
$form['my_survey']=$this->admin_model->getRecordQuery($query1.$queryLimit);
$form["links1"] = $this->pagination->create_links();

对于第二页

$config = array();
$config["base_url"] = base_url();
$config["total_rows"] = $this->admin_model->record_count($query2);
$config["per_page"] = 5;
$config["uri_segment"] = 3;
$config['use_page_numbers'] = TRUE;
$choice = 3;
$config["num_links"] = floor($choice);          
$config['full_tag_open'] = '<ul class="pagination1">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$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>';
$config['prefix'] = "";
$config['suffix'] = "/".$this->uri->segment(4)."/";
$config['first_url'] = base_url()."/0/".$this->uri->segment(4)."/";
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? (($this->uri->segment(3)*$config["per_page"])-$config["per_page"]) : 0;
$queryLimit =" LIMIT $page, {$config["per_page"]}";
$form['form']=$this->admin_model->getRecordQuery($query2.$queryLimit);
$form["links"] = $this->pagination->create_links();

您应该对同一页面上的多个网格和分页使用服务器端分页。我正在使用数据表作为单个网格,您可以从此示例中获取想法。

加载视图

public function index(){
if($this->session->userdata('id')){
$search = trim($this->input->post('search'));
$config = array();
$config["base_url"] = base_url() . "user";
//$config["total_rows"] = $this->user_model->count($search);
$config["per_page"] = 20;
$config["uri_segment"] = 2;
$config['use_page_numbers'] = TRUE;
$config['query_string_segment'] = 'per_page';
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
//  $page   = trim($this->input->post('page'));
$data["search"] = $search;
//$data["list"] = $this->user_model->userList($search, $page,  $config["per_page"]);
$data["links"] = $this->pagination->create_links();
if($page > 1) {
$data["sno"] = (($page*$config["per_page"])-$config["per_page"]);
} else {
$data["sno"] = 0;
}
$this->load->view('user', $data);
}else{
//load login view
redirect(base_url());
}
}

接口函数

public function list() {
if($this->session->userdata('id')){
$search = trim($this->input->post('search'));
$orderColumn = (int) $_GET['order'][0]['column'];
$orderBy = $_GET['columns'][$orderColumn]['name'];
$orderType = $_GET['order'][0]['dir'];
$draw = $_GET['draw'];
$start = $_GET['start'];
$length = $_GET['length'];
/*/ Make search Array /*/
//$search = array();
$str = $_GET['search']['value'];
if ($str != '') {
for ($i = 0; $i < count($_GET['columns']); $i++) {
$requestColumn = $_GET['columns'][$i];
if ($requestColumn['searchable'] == 'true') {
$search[$requestColumn['name']] = $str;
}
}
}
/*/ Get count of records /*/
$recordsTotal = $this->user_model->count($search);
$list_outlier = $this->user_model->userList($start, $length, $orderBy, $orderType, $search);
/*/ Make data array to be display /*/
$data = array();
if (is_array($list_outlier) && !empty($list_outlier)) {
$count = $start;
/*/ If order by Serial Number with descending /*/
if ($orderColumn == 0 && $orderType == 'desc') {
$count = (($recordsTotal - $start) + 1 );
}
foreach ($list_outlier as $key => $value) {
if ($orderColumn == 0 && $orderType == 'desc') {
$count--;
} else {
$count++;
}
$data[$key][] = !empty($value->member_name)?$value->member_name:'N/A';
$data[$key][] = !empty($value->member_type)?$value->member_type:'N/A';
$data[$key][] = !empty($value->mobile)?$value->mobile:'N/A';
$data[$key][] = !empty($value->email)?$value->email:'N/A';
//$data[$key][] = !empty($value->id)?$value->id:'N/A';
$html = '
<div class="input-group-btn">
<a class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-bars"></i></a>
<div class="dropdown-menu dropdown-menu-right">
<li>
<a class="dropdown-item" href="#" onclick="getEventId('.$value->id.')" title="Edit" data-toggle="modal" data-target="#myModal5">
<i class="fa fa-pencil"></i> Edit
</a>
</li>';
if($value->isActive) {
$html .= '<li><a href="'.base_url().'user/status?id='.$value->id.'&action=0" class="dropdown-item btn-delete" title="Deactive"><i class="fa fa-thumbs-down" ></i> Deactive</li>';
} else {
$html .='<li><a href="'. base_url().'user/status?id='.$value->id.'&action=1" class="dropdown-item btn-delete" title="Aactive"><i class="fa fa-thumbs-up" ></i> Active</li>';
}
$html .='</div></div>';
$data[$key][] = $html;
}
}
$respose = array(
"draw" => ($draw + 1),
"recordsTotal" => $recordsTotal,
"recordsFiltered" => $recordsTotal,
"data" => $data
);
echo json_encode($respose);
}else{
//load login view
redirect(base_url());
}
}

视图

<table id="data_table_othc_dthc" class="table display table-bordered">
<thead>
<tr>
<th class="th-left">Name</th>
<th>Member Type</th>
<th>Mobile</th>
<th>Email</th>
<th class="th-action">Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
jQuery(document).ready(function(){
$('#data_table_othc_dthc').DataTable({
"columns": [
{"name": "member_name"},
{"name": "member_type"},
{"name": "mobile"},
{"name": "email"},
{"name": "id", searchable: false}
],
scrollX: true,
scrollCollapse: true,
"processing": true,
"serverSide": true,
"order": [ 0, 'ASC' ],
"ajax": "YOURDomain/user/list",
"pageLength": 20
});

}); //Document End
</script>

最新更新