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
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:
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. Looping 5000 times in view is a big pain!
Try to use Datatable server side processing feature. You can take a look here https://datatables.net/examples/data_sources/server_side
The demo is with 5M data and it's fast
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.