douwen9540 2019-03-16 14:11
浏览 110
已采纳

Codeigniter分页和List.js

I am trying to get pagination and list.js (sort and search) to work with my table.

I have tried any advice I can find online, the pagination works correctly, and list.js works correctly search and sort works. But only on the items on that page. I.E I have 13 records and 5 per page, so 3 pages. List.js only searches and sorts the records on that page. Not on the pages that arent displayed.

The code in my tickets controller is as follows

$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);

The code for my table view is as follows

<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>

My JS in the footer is as follows

<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>

Any help would be awesome!

  • 写回答

1条回答 默认 最新

  • duandou9931 2019-03-16 15:28
    关注

    I thought that list.js requried exisiting pagination to work. However, list.js does every thing on its on. So i removed all my codeigniter pagaition and it is working perfectly.

    For anyones reference in the furture my controller now looks as so

     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);
    
    
    
    }
    

    And my JS in the footer as follows

    <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀