简体   繁体   English

我正在使用具有数据表的CodeIgniter框架,数据加载速度非常慢

[英]I am working on CodeIgniter framework with datatables and data loading speed is very slow

I am using datatable for many purposes like pagination, search, hide/show column etc but when it comes to load data to the page it take a lot of time .There are round about 5000 entries in database let me show you the code here for proper understanding 我将数据表用于许多目的,例如分页,搜索,隐藏/显示列等,但是将数据加载到页面时需要花费很多时间。数据库中大约有5000个条目让我向您展示代码正确理解
Datatables Script: 数据表脚本:

  <script type="text/javascript">
   $(document).ready( function () {
   oTable = $('#myTable , #complete_ride , #incomplete_ride').DataTable({
   "dom": 'Btip',
   "deferRender": true,
   "ordering" : false,
   "pageLength": 20,
   "order": [[ 0, "desc" ]],
   "scrollX": true,
  buttons: ['colvis','excel' , 'csv'],
  });

 $('#search_item').keyup(function(){
  oTable.search($(this).val()).draw();
  });
  $('input.toggle').on( 'click', function (e) {
    e.preventDefault();

    // Get the column API object
    var column = oTable.column( $(this).attr('data-column') );
    // Toggle the visibility
    column.visible( ! column.visible() );
 });
 });
 </script>

Here is the code of Controller: 这是Controller的代码:

function index()
{
 $data['user_basic'] = $this->User_basic_model->get_all_user_basic();
 $data['_view'] = 'user_basic/index';
 $this->load->view('layouts/main',$data);
}

and code of model: 和型号代码:

 function get_all_user_basic()
 {
    $this->db->order_by('user_id', 'desc');
    $this->db->select('table1.user_id,
                       table1.full_name,
                       table1.email,
                       table1.phone,
                       table1.password,
                       table1.date_of_birth,
                       table1.gender,
                       table1.address,
                       table1.cnic_no,
                       table1.reg_no,
                       table1.status,
                       table1.access_level,
                       table2.institute_id,
                       table2.institute_name,
                       table3.department_id,
                       table3.department_name,
                       table1.total_rides,
                       table1.total_distance,
                       table1.total_calories,
                       table1.wallet_amount,
                       table1.wallet_expiry,
                       table1.reffered_by,
                       table1.refferel_key,
                       table1.failed_login_attempts,
                       table1.last_login,
                       table1.last_login_ip,
                       table1.creation_date,
                       table1.update_date,
                       table1.delete_date,
                       table1.total_time');
    $this->db->from('table1');
    $this->db->join('table2' , 'table1.institute_id = table2.institute_id' , 'left outer');
    $this->db->join('table3' , 'table1.department_id = table3.department_id' , 'left outer');
    return $this->db->get()->result_array();
}

I think it's because you display all of your 5000 entries to the view. 我认为这是因为您向视图显示了所有5000个条目。 Looping 5000 times in view is a big pain! 循环观看5000次是一个很大的痛苦!

Try to use Datatable server side processing feature. 尝试使用Datatable服务器端处理功能。 You can take a look here https://datatables.net/examples/data_sources/server_side 您可以在这里看看https://datatables.net/examples/data_sources/server_side

The demo is with 5M data and it's fast 演示具有5M数据,并且速度很快

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM