Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables - on page load, table layout does not load instantly

There's a problem with datatables.js - when the page loads, the css with pagination is slightly delayed, so the whole data shows very quickly initally before it shows the css with pagination.

The same problem shows on this fiddle, when reloading the page you can see that it blinks, showing first the table without pagination, then with pagination (but the effect is very fast on this fiddle especially on chrome; on firefox it's slower and more noticable (for me), but on my application it is very noticable and bad looking.
Datatables example

I have tried to order styles and scripts, also trying to put things in the footer (currently it's all in the header) but it doesn't seem to matter. I also found another fiddle with datatables which shows the same thing on page load: ( some other datatables example ). Is it a bug?

Here are scripts and styles involved:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"  type="text/css" rel="stylesheet">

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" type="text/javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.15/js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="{{ base_url }}application/assets/js/datatablejs.js" type="text/javascript"></script>
like image 852
Galivan Avatar asked May 09 '17 20:05

Galivan


People also ask

What is better than DataTables?

The best alternative is jQuery Dynatable. It's not free, so if you're looking for a free alternative, you could try List. js or Webix DataTable. Other great apps like DataTables are Frappe DataTable, Dash DataTable, wpDataTables and Essential JS 2 for JavaScript by Syncfusion.

How does DataTables pagination work?

DataTables can split the rows in tables into individual pages, which is an efficient method of showing a large number of records in a small space. The end user is provided with controls to request the display of different data as the navigate through the data.

What is Deferrender in DataTables?

This option allows DataTables to create the nodes (rows and cells in the table body) only when they are needed for a draw.

How much data can DataTables handle?

The maximum number of rows that a DataTable can store is 16,777,216.


1 Answers

As per the comment:

CSS:

#list {
    display: none;
}

JS:

$('#list').DataTable({
    "columns": [ 
        { 
            "width": "45%" 
        }, 
        null, 
        null
    ],
    "initComplete": function(){ 
        $("#list").show(); 
    }
});

Working JSFidlle here. Hope that helps.

like image 181
annoyingmouse Avatar answered Sep 29 '22 08:09

annoyingmouse