laravel-datatables: Data loading is very slow for big number of rows.
Summary of problem or feature request
I tried to implement Datatable with Laravel but I have problem when my table has big number of rows because Datatable get ALL in one request and then pagination is on JS side. Can I use Laravel pagination or can I return paginated rows with paginate()
method from Eloquent on ajax method ? Because this is big problem for my project. Data loading is very slow. When I search some word processing is also very slow and after some operation like sort
, search
etc. Page freeze and nothing happen.
I hope that someone has same problem like this.
Code snippet of problem
serverSide: true,
processing: true,
render: true,
columns: [
{data: 'code'},
{data: 'name', "defaultContent": "<i>Not set</i>"},
{data: 'native_name', "defaultContent": "<i>Not set</i>"},
{data: 'action'}
],
ajax: '{!! route('dt-languages') !!}'
System details
- Operating System Linux
- PHP Version 7.0.4
- Laravel Version 5.4
- Laravel-Datatables Version 7.2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (4 by maintainers)
You need to remove get to use the query builder.
I am suffering from the problem. Slow rendering. My server side query.
help me. Should I write my own script to paginate? what should I do? I have records of more than 4,000,000 products. @yajra very appreciating if you help me.
I got this one too, may be the datatable request not chaining the pagination param to the query?
Glad I was able to help! Thanks!
My testing results:
First query:
select count(*) as aggregate from (select '1' as row_count from languages where languages.deleted_at is null and languages.deleted_at is null) count_row_table
-> 3.64msSecond query:
select languages.* from languages where languages.deleted_at is null order by code asc limit 10 offset 0
-> 1.05msThanks @yajra once again for help.