Mohamed Sabry
Mohamed Sabry

Reputation: 11

datatables with php and mysql large amount of data over 10000 records

I'm using table-striped Datatables with my admin panel script and when try to display large amount of data from mySQL and PHP it take lots of time to load page.

Below is code using with datatables:

<script>

    'use strict'; var Site = window.Site;

    $(document).ready(function($) { Site.run(); });

    (function() 
    {
        $(document).ready(function() 
        {
            var defaults = $.components.getDefaults("dataTable");

            var options = $.extend(true, {}, defaults, 
            {
                "aoColumnDefs": 
                [{ 'bSortable': false, 'aTargets': [-1] }],

                "iDisplayLength": 10,

                "aLengthMenu": 
                [
                  [5, 10, 25, 50, -1],
                  [5, 10, 25, 50, "All"]
                ],

                "sDom": '<"dt-panelmenu clearfix"Tfr>t<"dt-panelfooter clearfix"ip>',
                "oTableTools": { "sSwfPath": "../assets/vendor/datatables-tabletools/swf/copy_csv_xls.swf" }
            });

            $('#exampleTableTools').dataTable(options);
        });
    })();

</script>

How to load all records and in same load page faster.

Upvotes: 0

Views: 2851

Answers (2)

grusl83
grusl83

Reputation: 152

Like the others said. If you load 1000 entries at once, the page will be slow. For that purpose you need to enable pagination:

'bPaginate': true

Also you should enable bProcessing with large amount of data:

'bProcessing':true

Use server side processing for faster speed, with an external .php file:

    'bServerSide':true
    'sAjaxSource': 'your_external_get_data.php'

Check out the documentation for more info: http://legacy.datatables.net/usage/features

Upvotes: 0

Parth Sureliya
Parth Sureliya

Reputation: 256

if you need a large amount of data than you have to set limits and pagination in php. The data table is set to limit after getting all of the data. if you have larger data thank its necessary to set pagination in php.

Upvotes: 1

Related Questions