Codeigniter 分页和 List.js
Codeigniter Pagination and List.js
我正在尝试让分页和 list.js(排序和搜索)与我的 table 一起工作。
我已经尝试了我可以在网上找到的所有建议,分页工作正常,list.js 工作正常,搜索和排序工作正常。但仅限于该页面上的项目。 I.E 我有 13 条记录,每页 5 条,所以 3 页。 List.js 仅搜索和排序该页面上的记录。不在未显示的页面上。
我的tickets controller中的代码如下
$data['main_view'] = "tickets/index";
//loading pagination library
$this->load->library('pagination');
$query = $this->db->get('tickets','5',$this->uri->segment(3));
$data['tickets'] = $query->result();
//get all tickets
$query2 = $this->db->get('tickets');
$config['base_url'] = 'http://localhost/helpdesk/tickets/index/';
$config['total_rows'] = $query2->num_rows();
$config['per_page'] = 5;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_tag_open'] = '<li>';
$config['last_tag_open'] = '<li>';
$config['next_tag_open'] = '<li>';
$config['prev_tag_open'] = '<li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_close'] = '</li>';
$config['next_tag_close'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class=\"active\"><span><b>";
$config['cur_tag_close'] = "</b></span></li>";
$this->pagination->initialize($config);
$this->load->view('layouts/main',$data);
我的table视图代码如下
<div id="tickets">
<input class="search" placeholder="Search" />
<table class="table table-hover">
<thead>
<tr class=table-danger>
<th class="sort" data-sort="Title">
Title
</th>
<th class="sort" data-sort="Creator">
Creator
</th>
<th class="sort" data-sort="Date">
Date
</th>
<th class="sort" data-sort="SLA">
Service Level Agreement
</th>
<th class="sort" data-sort="Status">
Status
</th>
</tr>
</thead>
<tbody class="list">
<?php
foreach($tickets as $ticket):?>
<?php if($ticket->sla == 1){ ?>
<tr style='background-color: #e6dfcb;'>
<?php echo "<td class = 'Title'><a href = '". base_url() ."tickets/display/".$ticket->ticket_id ." '>". $ticket->ticket_title. "</a></td>"; ?>
<?php echo "<td class = 'Creator'>". $ticket->ticket_creator. "</td>"; ?>
<?php echo "<td class = 'Date'>". $ticket->ticket_date_reported. "</td>"; ?>
<?php echo "<td class = 'SLA'>". 'Elevated'. "</td>"; ?>
<?php if($ticket->Status == 0){
echo "<td class = 'Status'>". 'Open'. "</td>"; }
elseif($ticket->Status == 1){
echo "<td class = 'Status'>". 'Hold'. "</td>"; }
elseif($ticket->Status == 2){
echo "<td class = 'Status'>". 'Awaiting End User'. "</td>"; }
elseif($ticket->Status == 3){
echo "<td class = 'Status'>". 'Resolved'. "</td>"; }
elseif($ticket->Status == 4){
echo "<td class = 'Status'>". 'Closed'. "</td>"; }
else{
echo "<td class = 'Status'>". 'Unknown'. "</td>"; }?>
<td><a class = "btn btn-warning" href="<?php echo base_url();?>tickets/edit/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-edit"></span></a></td>
<td><a class = "btn btn-danger" href="<?php echo base_url();?>tickets/delete/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>
<?php }
elseif($ticket->sla ==2){?>
<tr style='background-color: #e6cbe6;'>
<?php echo "<td class = 'Title'><a href = '". base_url() ."tickets/display/".$ticket->ticket_id ." '>". $ticket->ticket_title. "</a></td>"; ?>
<?php echo "<td class = 'Creator'>". $ticket->ticket_creator. "</td>"; ?>
<?php echo "<td class = 'Date'>". $ticket->ticket_date_reported. "</td>"; ?>
<?php echo "<td class = 'SLA'>". 'Contract'. "</td>"; ?>
<?php if($ticket->Status == 0){
echo "<td class = 'Status'>". 'Open'. "</td>"; }
elseif($ticket->Status == 1){
echo "<td class = 'Status'>". 'Hold'. "</td>"; }
elseif($ticket->Status == 2){
echo "<td class = 'Status'>". 'Awaiting End User'. "</td>"; }
elseif($ticket->Status == 3){
echo "<td class = 'Status'>". 'Resolved'. "</td>"; }
elseif($ticket->Status == 4){
echo "<td class = 'Status'>". 'Closed'. "</td>"; }
else{
echo "<td class = 'Status'>". 'Unknown'. "</td>"; }?>
<td><a class = "btn btn-warning" href="<?php echo base_url();?>tickets/edit/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-edit"></span></a></td>
<td><a class = "btn btn-danger" href="<?php echo base_url();?>tickets/delete/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>
<?php }
else{?>
<tr>
<?php echo "<td class = 'Title'><a href = '". base_url() ."tickets/display/".$ticket->ticket_id ." '>". $ticket->ticket_title. "</a></td>"; ?>
<?php echo "<td class = 'Creator'>". $ticket->ticket_creator. "</td>"; ?>
<?php echo "<td class = 'Date'>". $ticket->ticket_date_reported. "</td>"; ?>
<?php echo "<td class = 'SLA'>". 'Basic'. "</td>"; ?>
<?php if($ticket->Status == 0){
echo "<td class = 'Status'>". 'Open'. "</td>"; }
elseif($ticket->Status == 1){
echo "<td class = 'Status'>". 'Hold'. "</td>"; }
elseif($ticket->Status == 2){
echo "<td class = 'Status'>". 'Awaiting End User'. "</td>"; }
elseif($ticket->Status == 3){
echo "<td class = 'Status'>". 'Resolved'. "</td>"; }
elseif($ticket->Status == 4){
echo "<td class = 'Status'>". 'Closed'. "</td>"; }
else{
echo "<td class = 'Status'>". 'Unknown'. "</td>"; }?>
<td><a class = "btn btn-warning" href="<?php echo base_url();?>tickets/edit/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-edit"></span></a></td>
<td><a class = "btn btn-danger" href="<?php echo base_url();?>tickets/delete/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>
<?php
}
endforeach; ?>
</tbody>
</table>
<ul class ="pagination"></ul>
<?php echo $this->pagination->create_links(); ?>
</div>
我在页脚的JS如下
<script type = "text/javascript" src="<?php echo base_url();?>assets/js/list.min.js"></script>
<script type = "text/javascript">
var options = {
valueNames: ['Title', 'Creator', 'SLA', 'Date','Status']
page: 3,
pagination: true
};
var tickets = new List('tickets', options);
</script>
任何帮助都会很棒!
我认为 list.js 需要现有分页才能工作。但是,list.js 会尽其所能。所以我删除了我所有的 codeigniter pagaition,它工作得很好。
供以后任何人参考,我的控制器现在看起来是这样
public function index() {
$user_id = $this->session->userdata('user_id');
$status = $this->user_model->get_privileged($user_id);
$privileged = $status->privileged;
//calling the get tickets function from ticket model.
if($privileged == 1){ $data['tickets'] = $this->ticket_model->get_tickets();}
else {
$data['tickets'] = $this->ticket_model->get_all_tickets($user_id);
}
$data['main_view'] = "tickets/index";
$this->load->view('layouts/main', $data);
}
还有我在页脚的JS如下
<script type = "text/javascript" src="<?php echo base_url();?>assets/js/list.min.js"></script>
<script type = "text/javascript">
var options = {
valueNames: ['Title', 'Creator', 'SLA', 'Date','Status'],
page:6,
pagination: true
};
var tickets = new List('tickets', options);
</script>
我正在尝试让分页和 list.js(排序和搜索)与我的 table 一起工作。
我已经尝试了我可以在网上找到的所有建议,分页工作正常,list.js 工作正常,搜索和排序工作正常。但仅限于该页面上的项目。 I.E 我有 13 条记录,每页 5 条,所以 3 页。 List.js 仅搜索和排序该页面上的记录。不在未显示的页面上。
我的tickets controller中的代码如下
$data['main_view'] = "tickets/index";
//loading pagination library
$this->load->library('pagination');
$query = $this->db->get('tickets','5',$this->uri->segment(3));
$data['tickets'] = $query->result();
//get all tickets
$query2 = $this->db->get('tickets');
$config['base_url'] = 'http://localhost/helpdesk/tickets/index/';
$config['total_rows'] = $query2->num_rows();
$config['per_page'] = 5;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_tag_open'] = '<li>';
$config['last_tag_open'] = '<li>';
$config['next_tag_open'] = '<li>';
$config['prev_tag_open'] = '<li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_close'] = '</li>';
$config['next_tag_close'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class=\"active\"><span><b>";
$config['cur_tag_close'] = "</b></span></li>";
$this->pagination->initialize($config);
$this->load->view('layouts/main',$data);
我的table视图代码如下
<div id="tickets">
<input class="search" placeholder="Search" />
<table class="table table-hover">
<thead>
<tr class=table-danger>
<th class="sort" data-sort="Title">
Title
</th>
<th class="sort" data-sort="Creator">
Creator
</th>
<th class="sort" data-sort="Date">
Date
</th>
<th class="sort" data-sort="SLA">
Service Level Agreement
</th>
<th class="sort" data-sort="Status">
Status
</th>
</tr>
</thead>
<tbody class="list">
<?php
foreach($tickets as $ticket):?>
<?php if($ticket->sla == 1){ ?>
<tr style='background-color: #e6dfcb;'>
<?php echo "<td class = 'Title'><a href = '". base_url() ."tickets/display/".$ticket->ticket_id ." '>". $ticket->ticket_title. "</a></td>"; ?>
<?php echo "<td class = 'Creator'>". $ticket->ticket_creator. "</td>"; ?>
<?php echo "<td class = 'Date'>". $ticket->ticket_date_reported. "</td>"; ?>
<?php echo "<td class = 'SLA'>". 'Elevated'. "</td>"; ?>
<?php if($ticket->Status == 0){
echo "<td class = 'Status'>". 'Open'. "</td>"; }
elseif($ticket->Status == 1){
echo "<td class = 'Status'>". 'Hold'. "</td>"; }
elseif($ticket->Status == 2){
echo "<td class = 'Status'>". 'Awaiting End User'. "</td>"; }
elseif($ticket->Status == 3){
echo "<td class = 'Status'>". 'Resolved'. "</td>"; }
elseif($ticket->Status == 4){
echo "<td class = 'Status'>". 'Closed'. "</td>"; }
else{
echo "<td class = 'Status'>". 'Unknown'. "</td>"; }?>
<td><a class = "btn btn-warning" href="<?php echo base_url();?>tickets/edit/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-edit"></span></a></td>
<td><a class = "btn btn-danger" href="<?php echo base_url();?>tickets/delete/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>
<?php }
elseif($ticket->sla ==2){?>
<tr style='background-color: #e6cbe6;'>
<?php echo "<td class = 'Title'><a href = '". base_url() ."tickets/display/".$ticket->ticket_id ." '>". $ticket->ticket_title. "</a></td>"; ?>
<?php echo "<td class = 'Creator'>". $ticket->ticket_creator. "</td>"; ?>
<?php echo "<td class = 'Date'>". $ticket->ticket_date_reported. "</td>"; ?>
<?php echo "<td class = 'SLA'>". 'Contract'. "</td>"; ?>
<?php if($ticket->Status == 0){
echo "<td class = 'Status'>". 'Open'. "</td>"; }
elseif($ticket->Status == 1){
echo "<td class = 'Status'>". 'Hold'. "</td>"; }
elseif($ticket->Status == 2){
echo "<td class = 'Status'>". 'Awaiting End User'. "</td>"; }
elseif($ticket->Status == 3){
echo "<td class = 'Status'>". 'Resolved'. "</td>"; }
elseif($ticket->Status == 4){
echo "<td class = 'Status'>". 'Closed'. "</td>"; }
else{
echo "<td class = 'Status'>". 'Unknown'. "</td>"; }?>
<td><a class = "btn btn-warning" href="<?php echo base_url();?>tickets/edit/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-edit"></span></a></td>
<td><a class = "btn btn-danger" href="<?php echo base_url();?>tickets/delete/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>
<?php }
else{?>
<tr>
<?php echo "<td class = 'Title'><a href = '". base_url() ."tickets/display/".$ticket->ticket_id ." '>". $ticket->ticket_title. "</a></td>"; ?>
<?php echo "<td class = 'Creator'>". $ticket->ticket_creator. "</td>"; ?>
<?php echo "<td class = 'Date'>". $ticket->ticket_date_reported. "</td>"; ?>
<?php echo "<td class = 'SLA'>". 'Basic'. "</td>"; ?>
<?php if($ticket->Status == 0){
echo "<td class = 'Status'>". 'Open'. "</td>"; }
elseif($ticket->Status == 1){
echo "<td class = 'Status'>". 'Hold'. "</td>"; }
elseif($ticket->Status == 2){
echo "<td class = 'Status'>". 'Awaiting End User'. "</td>"; }
elseif($ticket->Status == 3){
echo "<td class = 'Status'>". 'Resolved'. "</td>"; }
elseif($ticket->Status == 4){
echo "<td class = 'Status'>". 'Closed'. "</td>"; }
else{
echo "<td class = 'Status'>". 'Unknown'. "</td>"; }?>
<td><a class = "btn btn-warning" href="<?php echo base_url();?>tickets/edit/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-edit"></span></a></td>
<td><a class = "btn btn-danger" href="<?php echo base_url();?>tickets/delete/<?php echo$ticket->ticket_id?>"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr>
<?php
}
endforeach; ?>
</tbody>
</table>
<ul class ="pagination"></ul>
<?php echo $this->pagination->create_links(); ?>
</div>
我在页脚的JS如下
<script type = "text/javascript" src="<?php echo base_url();?>assets/js/list.min.js"></script>
<script type = "text/javascript">
var options = {
valueNames: ['Title', 'Creator', 'SLA', 'Date','Status']
page: 3,
pagination: true
};
var tickets = new List('tickets', options);
</script>
任何帮助都会很棒!
我认为 list.js 需要现有分页才能工作。但是,list.js 会尽其所能。所以我删除了我所有的 codeigniter pagaition,它工作得很好。
供以后任何人参考,我的控制器现在看起来是这样
public function index() {
$user_id = $this->session->userdata('user_id');
$status = $this->user_model->get_privileged($user_id);
$privileged = $status->privileged;
//calling the get tickets function from ticket model.
if($privileged == 1){ $data['tickets'] = $this->ticket_model->get_tickets();}
else {
$data['tickets'] = $this->ticket_model->get_all_tickets($user_id);
}
$data['main_view'] = "tickets/index";
$this->load->view('layouts/main', $data);
}
还有我在页脚的JS如下
<script type = "text/javascript" src="<?php echo base_url();?>assets/js/list.min.js"></script>
<script type = "text/javascript">
var options = {
valueNames: ['Title', 'Creator', 'SLA', 'Date','Status'],
page:6,
pagination: true
};
var tickets = new List('tickets', options);
</script>