Styling for the DataTable disappears upon loading jQuery

my PHP file named "zero3data.php"

<?php  
        printf('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" width="100%">');
        printf('<thead>');
        printf('<tr>');
        printf('<th rowspan="2">#</th>');
        printf('<th rowspan="2">Reference</th>');
        printf('<th rowspan="2">Customer</th>');
        printf('<th rowspan="2">Unit</th>');
        printf('<th rowspan="2">Payment</th>');
        printf('<th rowspan="2">Accessories</th>');
        printf('<th rowspan="2">Points</th>');
        printf('<th rowspan="2">Log</th>');
        printf('<th colspan="2">Approval</th>');
        printf('</tr>');
        printf('<tr>');
        printf('<th>Group Manager</th>');
        printf('<th>Main Branch</th>');
        printf('</tr>');
        printf('</thead>');
        printf('<tbody>');                                  

            require_once("config/db.php");
            $db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
            $result = $db_connection->query('SELECT * FROM reservationvw ORDER by logsubmit DESC');
            for($i=1;$row=$result->fetch_object();$i++) {               
                printf("<tr class='gradeC'>");      
                    printf("<td class='center'>%d</td>", $i);                       
                    printf("<td class='center'>%s</td>", $row->reference);
                    printf("<td class='center'>%s <br/> %s</td>", strtoupper($row->cust_name), $row->cust_addr);                
                    printf("<td class='center'>%s/%s/%s/%s/%s</td>", $row->model, $row->variant, $row->enginefuel, $row->transmission, $row->color);
                    printf("<td class='center'>%s/%s</td>", $row->payment, $row->insurance);                        
                    printf("<td class='center'>%s</td>", $row->accessories);
                    printf("<td class='center'>%3d</td>", $row->points);    
                    printf("<td class='center'>%s</td>", $row->logsubmit);
                    printf("<td class='center'>%s</td>", $row->approved);
                    printf("<td class='center'>%s</td>", $row->main_approved);                      
                printf("</tr>");
            }   
            printf('</tbody>');
            printf('</table>');

        ?>

my div tag in zero1.php

<body id="dt_example">      
            <div id="container"> 
                <div id="demo"> 
                         <div id="content"></div>
                </div> 
            <div>  
</body>

I have a script that loads my PHP file into the "content" section. The table structure is rendered correctly, but the CSS styling is missing. My table is customized with the DataTables plugin, which can be found here: http://datatables.net/usage/. Here's my script:

<script>    
$(document).ready(function(){
$('#content').load('zero3data.php'); 
});
</script>

Here are some methods I've tried to fix the missing CSS styling issue:

 $.ajax({
    url: 'zero3data.php',
    success: function(data) {    
    $("#content").html(data).trigger('create');
    }
    });
$('#content').load('zero3data.php',function(){ $('#content').trigger('create'); });

I also copied necessary CSS styles from zero1.php to zero3data.php, thinking that reloading the styles might help.

Here's the head section from zero1.php:

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico" />

    <title>DataTables example</title>
    <style type="text/css" title="currentStyle">
        @import "../../media/css/demo_page.css";
        @import "../../media/css/demo_table.css";
    </style>

    <script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script>

    <!-- bootstrap -->
    <link href="../../css/bootstrap.css" rel="stylesheet">
    <script src="../../js/jquery-2.0.3.min.js"></script> 
    <script src="../../js/bootstrap.min.js"></script>

    <script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script>
    <script type="text/javascript" charset="utf-8">
        $(document).ready(function() {
            $('#example').dataTable();
        } );
    </script>

</head>

Answer №1

Swap out the @import statements with actual links.

<link rel="stylesheet" type="text/css" href="../../media/css/demo_page.css" />
<link rel="stylesheet" type="text/css" href="../../media/css/demo_table.css" />

Given that CSS will silently disregard unfamiliar elements, it's uncertain whether an error would display in the console.log. By using the format above, you can confirm the accurate paths by inspecting the style sheet directly within the web inspector.

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

Is there a way to determine if a container is overflowing at the top?

Currently, I am using Puppeteer to scrape Slack. My goal is to confirm whether I have scrolled to the very top of the channel feed. The issue arises because the channel feed does not actually scroll, making it impossible for me to utilize the method outli ...

The functionality of the JQuery $.post method may be compatible with Firefox but may encounter issues when

I've encountered an issue with my website where certain functions that update the database using $.post work perfectly in Firefox, but fail to function properly in Internet Explorer. I'm struggling to identify the root cause of this problem. Here ...

Customizing the appearance of a JavaScript countdown timer's output on an individual basis

I am currently working on customizing the appearance of a JavaScript date counter. My goal is to style the days, hours, minutes, and seconds individually. Ideally, I want each unit to be right-aligned within its own div, with specific left and top absolute ...

Is there a way to instantiate a new object within the same for loop without replacing the ones created in previous iterations?

My current issue with this exercise is that as I convert the first nested array into an object, the iteration continues to the next nested array and ends up overwriting the object I just created. I'm wondering how I can instruct my code to stop itera ...

React and Material UI: troubleshooting problems with layout columns

I'm working on a project with three columns and I want to include a column for removing each row. Is it possible to add a "removing" column on the right? If so, how can I go about doing it? VIEW CODESANDBOX: HERE const CustomTableRow = ({ row, index ...

The getList() function from Restangular is failing to return the expected JSON data

I'm facing an issue with retrieving data from a Restangular promise. Instead of receiving pure JSON data, I always end up with a promise object. Here is the response from my API: localhost:3000/api/meal { "status": "success", "data": [ { ...

Is it possible to combine the use of 'res.sendFile' and 'res.json' in the same code?

At the moment, my Express app utilizes a controller to manage routing. When a specific route is accessed, I trigger pagesController.showPlayer which sends back my index.html. This is what the controller looks like: 'use strict'; var path = requ ...

Incorporate functionality into a button using jQuery

I am working on a table that displays data in different levels (Parent, Child, Grandson). When I click on the parent row, it expands to show new rows related to the child level. Similarly, clicking on a child row reveals a third level known as the grandson ...

Issue encountered when assigning a new value to a private class property at a global scope in JavaScript

I am encountering an issue in my code where I define a private class member using "#", initialize it in the constructor, and then receive an error when attempting to set/access the value. Uncaught TypeError: Cannot read private member #mouse from an object ...

Implementing automatic token refreshing and automatic logout features in Vue

I am a novice web developer looking to enhance my skills. For my initial project, I decided to incorporate Laravel and Vue. My main objectives are to: Implement an auto-logout feature after 3 minutes of user inactivity Create an automatic ping to my token ...

Generate a custom Elementor shortcode dynamically using JavaScript

I have a custom-built website using WordPress and Elementor. I am running code through the html element in Elementor to display dropdown menus. When a value is selected from each dropdown and the button is clicked, the values are stored in variables and th ...

Guide for verifying the minimum and maximum values when selecting a particular product from a dropdown menu

My goal is to implement validation for the width textbox when a user selects a specific product from the dropdown menu. The validation should only allow the user to enter a value between 10 and 200. I have successfully retrieved the selected value, but I ...

the deactivation of my rollover class is being caused by my float class

With the assistance of a generous contributor on stackoverflow, I was able to overlay different colored CSS boxes onto various images. These boxes could be removed upon mouseover, revealing the images beneath. You can view the code I used on fiddle here. ...

Tips for enhancing the appearance of a React component

I have a redux form that doesn't look great, and I would like to style it. However, my project uses modular CSS loaders. The styling currently looks like this: import styled from 'styled-components'; const Input = styled.input` color: #4 ...

Updating Kendo by modifying the Angular model

While working on a project with Angular, I recently discovered the Kendo-Angular project available at . I successfully integrated Angular-Kendo into my project and it seems to be functioning well, except for updating models in the way I am accustomed to. ...

How can we determine the total number of mandatory fields in an AngularJS form?

Can you explain how to calculate the number of required fields in a form using AngularJS? In my form, there are two required fields (email and select view). I want to display the count on my page - showing 2 if email is filled, 1 if only email is filled, a ...

Guide to periodically updating and displaying a <b-img> element in VueJS

Recently delving into the world of JS and Vue. Within my Bootstrap-Vue project, there's an image element that looks like this: <b-img src="/api/camera" fluid alt="camera"></b-img> Whenever the page is refreshed, the br ...

Observing Gulp's behavior is quite peculiar - it seems to be running

I ran into a rather peculiar issue with gulp watch. In my system, I have two disk drives: D and E. Disk D is a section of my computer's hard disk drive, while disk E is a flash drive. Both disks contain a file named test.txt: D:\test\test ...

Performance of Nested Menus: A Technological Perspective

In an effort to condense a long stay, the marketing team is requesting our entire sitemap of 5000 pages be accessible through one menu. Despite a year of resistance, we have come to accept that this is inevitable and are now exploring potential technologie ...

Aligning content in CSS for cross-browser compatibility with Internet Explorer and Chrome

My CSS grid has grid items that can easily be centered in Chrome by using the justify-items:center property, creating a magical effect. However, this solution does not work in Internet Explorer as the items remain stuck to the left side. For reference: ht ...