How DataTables Handles Loading and Rendering Time Delay

Utilizing DataTables in conjunction with Bootstrap 4 for client-side processing while displaying approximately 2,000 records.

The loading time is acceptable, but upon refreshing the page (F5), I observe an unformatted DataTable briefly appearing. It seems like DataTables is the last element to load, making it quite noticeable.

For a demonstration, check out their 'Zero configuration' example. Upon refreshing the page, you can catch a glimpse of all the table records momentarily (you have to be quick!).

This issue is also apparent in the 'Bootstrap 4' example.

I have a couple of inquiries:

  • Why does this occur?
  • Is there a way to prevent it?

I've attempted rearranging my JS and CSS files (of which I have few), but it has had no impact. My concern is that as I add more records, the loading time will increase, making the unformatted DataTable more evident with each page load.

Answer №1

It appears that many others have encountered the same problem. This issue seems to be quite common, especially with DT.

For a helpful solution, check out this response Datatables - on page load, table layout does not load instantly

Answer №2

If you examine the Bootstrap 4 example you provided closely, you'll find a clue hidden within the code.

$(document).ready(function() {
    $('#example').DataTable();
} );

This code snippet indicates that when the document has finished loading, it will transform the element with the id example into a DataTable format.

To prevent this behavior, one workaround is to set the table's style to display: none.

Afterwards, you can include $('#example').show() in the code to reveal the table once it has been converted into a DataTable.

$(document).ready(function() {
    $('#example').DataTable();
    $('#example').show();
} );

Answer №3

In my opinion, it is not acceptable to have a long loading time when rendering 2000 rows or more. While loading time may be fine on PCs and laptops, it poses a problem for mobile devices. Have you tested this already?

Datatable is an excellent plugin with many options. You can initially render only 10 rows, and then request Datatable to draw and render additional pages when the user wants to see more. To achieve this, you need to use a data property like the one shown below:

HTML:

    <table id="example" class="table table-striped table-bordered" cellspacing="0">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Age</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>

JS:

var dataSet = new Array();
for(i=0;i<2000;i++){
    var item = new Array(
        "name "+i,
        "position "+i,
        "office "+i,
        "age "+i,
        "start date "+i,
        "salary "+i
    );
    dataSet.push(item);
}

tableMain = $("#example").DataTable({
    data: dataSet,
    columns: [
        {"orderable": true},
        {"orderable": true},
        {"orderable": true},
        {"orderable": true},
        {"orderable": true},
        {"orderable": true}
    ],
    pageLength: 10
});

By using this method, only 10 rows are rendered in the HTML code initially.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Cannot see the created item in Rails application when using RSpec, Capybara, Selenium, and JavaScript

Currently, I am in the process of developing a web store. The key functionality is already implemented where all products are displayed on one screen along with the list of ordered items. Whenever a product is selected for ordering, it should instantly app ...

What is the best way to convert exponential values to decimals when parsing JSON data?

var value = '{"total":2.47E-7}' var result = JSON.parse(value); Looking to convert an exponential value into decimal using JavaScript - any suggestions? ...

Experiencing problems with npm and bower installations, along with deprecated modules while setting up angular-phonecat project

Trying to execute npm install in terminal while setting up angular-phonecat based on instructions from https://docs.angularjs.org/tutorial Encountering issues with deprecated modules and errors during the bower install phase. Seeking advice on how to upd ...

The spawn function in the child_process module throws an error with the code -2, specifically the

Hey there, I'm working on creating an npx command that allows me to run child commands within my package.json bin: "bin": { "malzahar": "./src/bin/malzahar.js" }, Below is the code from my malzahar.js: #! /usr/bin/en ...

Executing a JavaScript function to interact with a nodeJS HTTP server

I'm currently setting up a basic nodeJS HTTP server. When accessing it from the browser with http://localhost:8081, everything runs smoothly. However, when I try to use a JS fetch() method, I encounter a 404 error: GET http://localhost/:8081?q=hi Ja ...

CSS modified after opening a modal dialog that has loaded external HTML content

Within my ASP.NET MVC project, I am utilizing a tab wizard. On one of the tabs, I trigger a modal dialog by loading HTML content from an external API. However, once I close the wizard and navigate to the next tab, the table style (specifically border color ...

Generating conference itinerary - establishing agenda function (Sequelize)

const _ = require('lodash'); const Promise = require('bluebird'); const Sequelize = require('sequelize'); const ResourceNotFound = require('./errors').ResourceNotFound; const ResourceAccessDenied = require('./er ...

Tips for restricting the voting feature on a Facebook App to only once every 24 hours

Recently, I've been delving into the world of back-end development and decided to create a Facebook app that allows multiple photo entries with voting capabilities. Users can vote on one or multiple entries each day, and the system automatically captu ...

Guide on Importing All Functions from a Custom Javascript File

As a beginner in learning Angular, I am faced with the task of converting a template into Angular. However, I am struggling to find a solution for importing all functions from a custom js file into my .component.ts file at once. I have already attempted t ...

prompting the JavaScript hangman game to identify the letters in the "selected word"

Currently, I am on a mission to teach myself Javascript and have taken on the challenge of creating a simple hangman game. This type of project is commonly used in interviews or tests, so it seemed like a great opportunity for practice. My approach involve ...

Tips for creating Card-Title responsiveness across various screen dimensions with Bootstrap 4

I'm a beginner in web design and I'm wondering if it's possible to adjust the font-size of the card-title and the size of the card image based on different screen sizes using bootstrap 4. When viewed on small screens, they appear too large. ...

Hide the selection box when hovering over the Div

Looking for a quick solution. I want the option drop down to close when another div element is hovered over. First, open the drop down and hover over the red element on the right side. When hovering over the red element, I would like the drop down to clos ...

Transferring a variable value between functions using autocomplete and AJAX communication

I am facing difficulties with implementing autocomplete jQuery along with AJAX call. The issue arises when a user enters text in the input field, triggering an AJAX POST request to the controller which retrieves values from the database and sends them back ...

The concept of CSS "preload" animation

When working with CSS, I encountered an issue with lag while loading 24 different mask images for a transition effect. To address this, I tried using a div called "preload" to cache the images and prevent lag on playback: <div class='trans' s ...

"Converting HTML code into visual templates for browser display - a step-by-step guide

I have a task to transform HTML into a template format. As shown in the image, the content needs to be displayed as a template. I currently use a table for display, but now I want to present it in a template output. Below is the code snippet: <table ...

Adjusting the properties of an Image Object using jQuery

I currently have an Image object setup like this: var img_BlinkingGreen = new Image(); img_BlinkingGreen.src = "Images/UIFiles/transparent-area.gif"; Now, I am trying to set attributes for the image object, a class, and a click event. However, I encounte ...

Header frame is not valid

I have been working on developing a real-time application using NodeJS as my server and Socket.IO to enable live updates. However, I encountered an error message that reads: WebSocket connection to 'wss://localhost:1234/socket.io/?EIO=3&transpo ...

Is it possible to activate the onChange event when the input value is being modified by the state with information obtained from a fetch

Currently, I am successfully fetching data from an API and storing it. However, I now want to incorporate a functionality where a user can paste a website URL into an input box, click a button, and then display the results in a return div UI. I am struggli ...

Accessing a global variable within a jQuery .each function

I'm struggling to modify the global variable within an each function var total_ctc_change = 0; $('.table' + employeeid + ' thead th').each(function(index, value){ total_ctc_change++; }); ...

Retrieve Content from a Different Web Page Using Ajax

I recently received permission from another website to pull their RSS feeds, and now I'm trying to figure out what to write in TAG1 and TAG2. This is the specific issue I'm facing: Here is the HTML code (it's an ajaxed page) <!doctype ht ...