如何使Codeigniter在表视图中显示所有条目而不限于10行数据?

时间:2018-11-15 09:30:36

标签: codeigniter

我研究无济于事,希望这里有人能提供帮助。

当前,数据将按照下面的视图在表中列出,并且CodeIgniter自动将页面限制为10行数据。 我不想要这个(10行数据)。

我需要在表中列出所有行而不分页。

非常感谢您的帮助。

查看代码(整个文件):

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Appointments</title>
    <?php  $this->load->view("admin/common/common_css"); ?>
    <!-- daterange picker -->
    <link rel="stylesheet" href="<?php echo base_url($this->config->item("theme_admin")."/plugins/daterangepicker/daterangepicker-bs3.css"); ?>">
    <link rel="icon" type="image/png" href="/images/favicon.png">
    <?php  $this->load->view("common/secretz_css"); ?>
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">

      <?php  $this->load->view("admin/common/common_header"); ?>
      <!-- Left side column. contains the logo and sidebar -->
      <?php  $this->load->view("admin/common/common_sidebar"); ?>

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header  sz-pink">
          <h1>
            TRACKING List
            <small> </small>
          </h1>

        </section>

        <!-- Main content -->
        <section class="content ">
            <div class="box">
                <div class="box-header">
                <form action="" method="post">
                    <input type="hidden" name="date_range" id="date_range_field" />
                    <input type="hidden" name="date_range_lable" id="date_range_lable" />

                    <div class="row">

                        <div class="col-md-4">
                            <div class="form-group">
                                <label>Date range:</label>
                                <div class="input-group"  style="width: 100%;" >
                                  <button class="btn btn-default form-control" style="width: 100%;" type="button" id="daterange-btn">
                                    <i class="fa fa-calendar"></i> <span id="reportrange"><?php if(!empty($date_range_lable)){ echo $date_range_lable; } else { echo date("M d, Y"); } ?></span> 
                                    <i class="fa fa-caret-down"></i>
                                  </button>

                                </div>
                            </div>    
                        </div>

                        <?php if(_get_current_user_type_id($this)==0){ ?>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label>Choose a specific Outlet:</label>
                                    <select class="form-control choosen" name="filter_outlet">
                                        <option value="">All outlets</option>
                                        <?php foreach($business as $bus){
                                            ?>
                                            <option value="<?php echo $bus->Store_Name ?>" 
                                                <?php if($this->input->post("filter_outlet") == $bus->Store_Name)
                                                        { echo "selected"; } ?> ><?php echo $bus->Store_Name; ?></option>
                                            <?php
                                        } ?>
                                    </select>
                                  </div>
                            </div>
                        <?php } ?>
                        <div class="col-md-1">
                            <label style="line-height: 20px; display: block;">&nbsp;</label>
                            <input type="submit" name="filter" class="btn btn-default " value="Filter" />
                        </div>

                    </div>

                </form>
                <?php $sumH1 = 0; $sumH2 = 0;   ?>
                <table id="example2" class="table table-bordered table-hover">
                    <thead>
                      <tr>
                        <th>header 1</th>
                        <th>header 2</th>
                        <th>header 3</th>
                      </tr>
                    </thead>
                    <tbody>
                        <?php foreach($business as $list){
                            $this->load->view("admin/tracking_list_row",array("list"=>$list)); 
                            $sumH1 += $list->c_H1;
                            $sumH2 += $list->c_H2;
                        } ?>
                        <tr>
                            <th align="right">TOTAL:</th>
                            <th align="center"><?php echo number_format($sumH1,0,".",","); ?></th>
                            <th align="right"><?php echo number_format($sumH2,2,".",","); ?></th>

                          </tr>
                    </tbody>
                </table>

            </div>
        </div>
        </section><!-- /.content -->
      </div><!-- /.content-wrapper --> 

      <?php  $this->load->view("admin/common/common_footer"); ?>  


      <!-- Add the sidebar's background. This div must be placed
           immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div><!-- ./wrapper -->

    <?php  $this->load->view("admin/common/common_js"); ?>
    <!-- date-range-picker -->
    <script src="<?php echo base_url($this->config->item("theme_admin")."/plugins/daterangepicker/moment.min.js"); ?>"></script>
    <script src="<?php echo base_url($this->config->item("theme_admin")."/plugins/daterangepicker/daterangepicker.js"); ?>"></script>

    <script>
      $(function () {

        $('#daterange-btn').daterangepicker(
            {
              ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Tommorrow': [moment().add(1, 'days'), moment().add(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Next 7 Days': [moment(), moment().add(6, 'days')],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'Next 30 Days': [moment(), moment().add(29, 'days')],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
              },
              startDate: moment().subtract(29, 'days'),
              endDate: moment()
            },
        function (start, end) {
          $('#reportrange').html(start.format('MMM D, YYYY') + ' - ' + end.format('MMM D, YYYY'));
          $('#date_range_lable').val(start.format('MMM D, YYYY') + ' - ' + end.format('MMM D, YYYY'));
          $('#date_range_field').val(start.format('YYYY-MM-D')+','+end.format('YYYY-MM-D'));
        }
        );

        $('#example2').DataTable({
          "paging": true,
          "lengthChange": false,
          "searching": true,
          "ordering": true,
          "info": true,
          "autoWidth": false
        });
        $("body").on("change",".tgl_checkbox",function(){
            var table = $(this).data("table");
            var status = $(this).data("status");
            var id = $(this).data("id");
            var id_field = $(this).data("idfield");
            var bin=0;
                                         if($(this).is(':checked')){
                                            bin = 1;
                                         }
            $.ajax({
              method: "POST",
              url: "<?php echo site_url("admin/change_status"); ?>",
              data: { table: table, status: status, id : id, id_field : id_field, on_off : bin }
            })
              .done(function( msg ) {
              //  alert(msg);
              }); 
        });
      });
    </script>
  </body>
</html>

控制器代码:

        $sql = "SELECT *
                FROM daily_sales";

        $q = $this->db->query($sql); 

        $data["business"] = $q->result(); 

        $this->load->view('admin/tracking_list',$data); 

SCREENSHOT显示显示的10行(希望在此处列出所有13个条目,没有分页):

enter image description here

1 个答案:

答案 0 :(得分:1)

检查以下输出:

  1. 在您的数据库中运行该查询,检查其是否返回10行或更多行

  2. Var_dump或print_r您的result()在控制器中,检查其是否有10行以上

    $sql = "SELECT *
            FROM daily_sales";
    $q = $this->db->query($sql); 
    var_dump($q->result());
    //$data["business"] = $q->result(); 
    //$this->load->view('admin/tracking_list',$data);
    
  3. 查看或查看您的$ business变量,检查它是否有10行以上

    <tbody>
      <?php
        var_dump($business);
        foreach($business as $list){
          $this->load->view("admin/tracking_list_row",array("list"=>$list)); 
          $sumH1 += $list->c_H1;
          $sumH2 += $list->c_H2;
          $sumH3 += $list->c_H3;
        }
      ?>
      <tr>
        ....
      </tr>
    </tbody>
    

像上面的评论一样,CI不会自动限制您的数据,因此它应该是限制数据行的一部分。我还不能发表评论,请原谅我在这里回答。

编辑: 那不是您的CI错误,而是您的 DataTable (看起来here)。更改以下代码:

$('#example2').DataTable({
"paging": false, //This one is the cause, change to false
"lengthChange": false,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": false
});