The information in the table quickly appears in its raw format before being formatted and enhanced by jquery DataTables

I have encountered an issue where table data loads briefly and unformatted before jquery DataTables kicks in. After doing some research, I found that many suggest hiding the table using CSS and then showing it using jQuery with initComplete. However, despite trying different approaches, I haven't been able to get it to work successfully:

css:
#tblAccount {
    visibility:hidden;
}
#tblCustomer {
    visibility: hidden;
}

jquery:
$(function () {
    $("[id*=tblAccount], [id *= tblCustomer]").prepend($("<thead></thead>").append($(this).find("tr:first"))).DataTable({
        "paging": true,
        "lengthChange": true,
        "searching": true,
        "ordering": true,
        "info": true,
        "autoWidth": true,
        "responsive": true,
        "dom": 'lBfrtip',
        "buttons": ['excel', 'print', 'pdfHtml5'],
        "initComplete": function () {
            $('#tblAccount').show().css({ visibility: "visible" });
        $('#tblCustomer').show().css({ visibility: "visible" });
        }

    });
})

Answer №1

Using both the .show() function and changing the css with css({ visibility: "visible" }) may not be necessary.

If you initially set #tblAccount and #tblCustomer with "display : none" and then use

$('#tblAccount').show();
$('#tblCustomer').show();

in the initComplete function, you should achieve the desired functionality.

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

Does Google Cloud CDN not store data from the storage bucket?

I've been experimenting with combining a Load Balancer, Cloud Storage, and CDN for the past few weeks. Unfortunately, I have not been successful in getting it to work as expected. I uploaded some static files (2 jpgs, svgs, and css files) to a multi- ...

Adjusting the height of a flexbox column to fit three rows within the space of two

Exploring the wonders of Flexbox and delving into its functionality. I have shared a Code Sandbox link showcasing my React /bootstrap code in progress... Currently, I am developing a clock component with two buttons for adjusting time (increase/decrease). ...

Using data-attribute, JavaScript and jQuery can be used to compare two lists that are ordered

I am looking to implement a feature that allows me to compare two lists using data attributes in either JavaScript or jQuery. Unfortunately, I haven't been able to find any examples of this online and I'm not sure how to approach it. The first l ...

Only the first element can trigger reactions in jQuery and Ajax!

I am facing an issue on this particular page where I have several forms that can be optionally submitted using ajax. The problem lies in the fact that only the first element selected by jQuery is getting executed! Below is the JavaScript code: $(function ...

What is the correct way to encode an HTML string in JavaScript?

I have identified a XSS Scripting vulnerability in my code and I want to prevent it. To do so, I am utilizing a Jquery Encoder for protection against XSS Scripting attacks. Below is the JavaScript code snippet: function test(response) { $('#test ...

Ways to dynamically incorporate input fields into a form

My current project involves managing an Asset Management system for a company with multiple locations. This system has the capability to return unused asset items back to storage. I am faced with the task of returning a large number of items, which requi ...

Comparing and highlighting words in strings using JavaScript

Seeking assistance with comparing and styling words as shown in the image below: https://i.stack.imgur.com/Ffdml.png I attempted using JavaScript for this task but have not been successful so far. <div class="form-group"> <div class="col-md ...

jquery animate won't trigger

<html> <head> <style type="text/css"> div#bg1 { height: 159px; width: 800px; margin-left: auto; margin-right: au ...

Understanding MUI5 prop handling

Recently, I decided to experiment with Material UI 5 sx props just for fun. I encountered a bit of confusion while trying to replicate the behavior of the previous MUI 4 makeStyles function. Specifically, I was attempting to pass JSS classnames to sx props ...

Does the media query max-width refer to the size of the viewport or the size of the window?

Can someone clarify whether the max-width in a media query is based on the viewport size or window size? For instance, consider this media query: @media screen and (max-width: 360px){} Would this media query be activated when the viewport reaches 360px ...

Customizing CSS for displayed MDBootrap components

I am currently using MDBoostrap, a styling tool similar to Bootstrap, in my React application. I have a select element that is coded like so: <div> <select id="Regions" style={errorSelect} value={this.state.userRegionId} onChange={this.handle ...

"Enhancing Your Website with a Preloader Loading GIF: Step-by-Step Guide

Can anyone assist me in implementing a preloader with a 'loading' gif image on my website that will display for a maximum of 5 seconds before the site fully loads? I've attempted various methods without success, so any help would be greatly ...

Invoke data-id when the ajax call is successful

Initially, there was a smoothly working "like button" with the following appearance: <a href="javascript:void();" class="like" id="<?php echo $row['id']; ?>">Like <span><?php echo likes($row['id']); ?></span ...

constructing an array in real-time with the help of jQuery

I am working with HTML checkboxes and trying to store the value of any checked checkbox in an array. However, my function is currently returning an empty array. var arry = []; function CheckBox(check) { debugger for (i = 0; i < check.length; i+ ...

What is the proper way to send an AJAX request with the data type set to

I am currently working on creating my own POST request. Below is the function I have written: function sendPost(o) { var h = new XMLHttpRequest(); h.onreadystatechange = requestComplete; function requestComplete() { if (h.readyState = ...

C# MVC alert platform

Currently developing a C# MVC 4 app and aiming to integrate a notification system similar to Facebook's. I am considering implementing a table for each event to store notifications, then using AJAX calls every minute to fetch notifications for the cu ...

retrieve the date value of Focus+Context by using the Brushing Chart

Currently, I am engaged in analyzing the sentiment of tweets on Twitter. The analysis will produce an overall area graph that allows me to choose a specific date range and extract all or some of the tweets falling within that range. In order to create a t ...

What is the best way to vertically center a column of images on mobile devices in a responsive manner?

Currently, I am developing an application that showcases the 9 newest photos with a specific tag. To ensure consistency in image sizes, I have set each photo to be 240px wide and 200px tall. My query now is how can I vertically center these images so they ...

Send the AJAX form identifier when submitting

There are multiple AJAX forms on the page which contain the same elements. I have a jQuery function that searches for child elements of the form and updates them on success. However, I need to find a way to pass the ID of the form that sent the request to ...

Retrieve the second offspring of a jQuery selection

I have searched extensively for a solution to this question, but haven't come across anything helpful. Here is the code snippet I am struggling with: $("table tbody tr").hover( function() { var secondCell = $(this).children[1].textContent; ...