When using the `console.log()` function in JavaScript, the table formatting may

I'm attempting to generate a table using JavaScript

Here's the HTML for the table:

<table id="rounded" runat=server  summary="2007 Major IT Companies' Profit" style="position:relative;left:-45px;"  >

    <tr>
        <th scope="col" class="rounded-company">header1</th>
    <th scope="col" class="rounded-q1">header2</th>

        <th scope="col" class="rounded-q1">header3</th>
         <th scope="col" class="rounded-q1">header4</th>
          <th scope="col" class="rounded-q1">header5</th>
           <th scope="col" class="rounded-q1">header6</th>
            <th scope="col" class="rounded-q1">header7</th>
             <th scope="col" class="rounded-q1">header8</th>

               <th scope="col" class="rounded-q1">header9</th>
               <th scope="col" class="rounded-q4"> header10</th>


    </tr>


</table>

The table data is fetched using AJAX, resulting in this updated table layout:

<table id="rounded" runat=server  summary="2007 Major IT Companies' Profit" style="position:relative;left:-45px;"  >

            <tr>
                <th scope="col" class="rounded-company">header1</th>
            <th scope="col" class="rounded-q1">header2</th>

                <th scope="col" class="rounded-q1">header3</th>
                 <th scope="col" class="rounded-q1">header4</th>
                  <th scope="col" class="rounded-q1">header5</th>
                   <th scope="col" class="rounded-q1">header6</th>
                    <th scope="col" class="rounded-q1">header7</th>
                     <th scope="col" class="rounded-q1">header8</th>

                       <th scope="col" class="rounded-q1">header9</th>
                       <th scope="col" class="rounded-q4"> header10</th>


            </tr>
<tr>
                <td>value1</td>
                <td>value2</td>

                <td>value3</td>
                <td>value4</td>
                <td></td>
                <td>value6</td>
                <td>value7</td>
                <td>value8</td>

                <td>value9</td>
                <td>value10</td>
            </tr>
            <tr>
                <td>value1</td>
                <td>value2</td>

                <td>value3</td>
                <td>value4</td>
                <td></td>
                <td>value6</td>
                <td>value7</td>
                <td>value8</td>

                <td>value9</td>
                <td>value10</td>
            </tr>

</table>

My script for printing the table looks like this:

<script type="text/javascript">
function printTable()

{


    var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
    disp_setting += "scrollbars=yes,width=1350, height=800";
    var content_vlue = $("#rounded").html();


    var docprint = window.open("", "", disp_setting);
    docprint.document.open();
    docprint.document.write('<link href="css/table2.css" type="text/css" rel="stylesheet" />');  
    docprint.document.write('<html><head><title>Inel Power System</title>');
    docprint.document.write('</head><body onLoad="self.print()"><center>');
    docprint.document.write(content_vlue);
    docprint.document.write('</center></body></html>');
    docprint.document.close();
    docprint.focus(); 
}

</script>

The issue I'm facing is that the printed table appears as text only, without rows or columns. When printing directly from the page source (without using AJAX), everything works correctly.

If anyone has any insights or solutions, I would greatly appreciate it. Thank you!

Answer №1

Make sure to insert the <table> element within your HTML code when creating a printed document. Using .html() only captures the content contained within the table tags.

Another approach is to enclose the table within another container (such as a <div>) and then do the following:

var updated_content = $('#container').parent().html();

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

Issue arises when using Ionic 7 tabs with standalone Angular components

Hey, I'm new to Ionic and trying to learn it. However, all the courses available are on the old versions 5 or 6. I attempted to learn it with Angular standalone but it didn't turn out as I expected. The new way of routing wasn't working for ...

The issue of transform scale not functioning properly in conjunction with background clip and gradients in CSS

Looking to transform a div with the transform: scale(-1,1) property while using background-clip: text on the text within it. However, this causes the text to disappear. Here's what I've attempted: .reverse { transform: scale(-1, 1); } .gr ...

Only displaying sub items upon clicking the parent item in VueJS

I'm in the process of designing a navigation sidebar with main items and corresponding sub-items. I want the sub-item to be visible only when its parent item is clicked, and when a sub-item is clicked, I aim for it to stand out with a different color. ...

Having a problem with the xmlhttprequest, not confident if it is being called correctly

I encountered a problem with the code I have where a user selects a sales center and it should trigger a currency change. Both selections are dropdowns, but when I choose a sales center, I receive an error saying ReferenceError: makeRequest is not define ...

Efficiently Populating Arrays Without Blocking

Let's dive into the scenario... Here is the template for our component <template> <div> <loader v-show="loading"></loader> // display loading animation <div v-show="!loading"> <div v-for="group in groups ...

The menu field remains open even after clicking on the menu

I have encountered an issue with my code. Here is a DEMO that I created on jsfiddle.net Currently, when you click on the red div, the menu opens. However, if you click on the menu items, the menu area does not close. What do I need to do in order to clo ...

How to Automatically Display the First Tab in Bootstrap 3

Having a dynamic modal with two tabs, I aim for #tab1 to always be the default tab upon opening the modal. The issue arises when the modal is opened, #tab2 is clicked, and then the modal is closed. Subsequent reopenings still display #tab2. See JSFiddle e ...

Using NGRX Effects to Load Data for a Specific Item in Angular

On my website, there is a page that displays a range of products from the store managed by a reducer called products. When an action PRODUCTS.LOAD_ALL is dispatched, it triggers an API call through an effect and then sends a PRODUCTS.LOAD_ALL_SUCCESS actio ...

The system encountered an issue: "Property 'add' is not defined and cannot be read."

I'm facing a dilemma with my exercise. Despite the numerous inquiries regarding this problem, I haven't been able to find a solution. I am hopeful that you can provide some assistance! Below is the code snippet in question: let myDivs = docume ...

Using setInterval() does not automatically fetch JSON data at a specified interval for me

Attempting to constantly update the latitude and longitude coordinates from a dynamic API has proven to be a challenge. Despite utilizing jQuery with a set interval of 1000 milliseconds, the data retrieval from the API does not occur as expected. While i ...

Grab the source attribute of the <img> tag (identified by class) across numerous HTML pages

Here is an example: A website has the URL , where xxxx represents an integer between 1 and 1935. On each page, there may be an <img class="thumbnail" src="Images\Robots\{robotname}.png">. However, not all pages have th ...

What is causing the components to not re-render after a state change in React?

I am attempting to retrieve data from the Coin Market Cap API and showcase the details in simple cards. I have experimented with various methods and included comments to document my trials. Any assistance would be greatly appreciated. This is the Parent: ...

The 3D sphere in Three.js appears to have a 2D visual effect

Hey there! I've recently delved into the world of three.js and I'm working on creating a captivating scene with 3D spheres and a simple rotation using orbit controls. However, I've encountered an issue where the spheres appear flattened or 2 ...

Including a 3DS card to a Stripe Client for recurring payments

I'm encountering an issue when trying to add payment cards with 3DS authentication for existing customers who already have an active monthly subscription. The objective is to allow our clients to change, remove, and add cards to the Stripe Customer ob ...

I'm having an issue with my Bootstrap tabs - they seem to be unresponsive when clicked

I've been working on a Bootstrap website and have run into some issues that I can't seem to resolve. One problem I encountered was with a set of tabs that were supposed to be interactive, but for some reason, they weren't working as expected ...

A simple way to initiate an AJAX call once the page has completed loading is by using the `window.location.href` as the

I encountered an issue with my event listener setup function navBtn() { $('#navBtn').on('click', (event) => { window.location.href = 'someotherfile.html'; myAJAXrequest(); }) } The problem I'm facing is that ...

Angular implementing a carousel feature using the ngFor directive

Currently, I am working on implementing a carousel feature. The images in the carousel are sourced from a string array and I want to be able to cycle through them when clicking on the left or right arrows. How can I achieve this functionality using only ...

What methods can be used to transfer data from mapped objects to their parent component in React?

I'm in the midst of creating a cutting-edge shopping cart application. Each item is beautifully displayed as a card component within the app. To achieve this, I've utilized mapping with dummy object data: const Home = () => { const dumm ...

Amend and refresh information using AJAX technology

My code isn't working as expected when I try to use AJAX to retrieve data from an editable form and update it in the database. Can someone help me find the issue? Below is the code I'm using: <?php $query = db_get_list("SELECT * FROM ...

I am looking for an alternative approach to retrieve the data from the controller in case of success instead of the method provided in the code below

In this code snippet, I am looking for an alternative way to retrieve data from the controller upon successful execution, rather than checking it as data.msg. I want to avoid using strings or boolean values like SuccessWithPass. Controller snippet: if ...