What causes the table formatting to disappear when displaying rows in a Vue component?

When I insert rows manually into my HTML table, all the styles look great. However, when I use Vue components with the v-for directive to render the rows, the columns in the table shift around. Here are the hardcoded rows:

 <table class="table_body">

                       <tr class="main_table_tr" >
                        <td class="main_table_td column_1">999999</td>
                        <td class="main_table_td column_2">0000000001</td>
                        ... (remaining content unchanged)
                    </tr>
                    <tr class="main_table_tr" >
                        <td class="main_table_td column_1">999999</td>
                        <td class="main_table_td column_2">0000000001</td>
                        ... (remaining content unchanged)
                    </tr>
                    ... (repeated rows omitted for brevity)
                </table>

Here are the rendered rows:

 <table class="table_body">
  <tr class="main_table_tr" is="app-skuins" :list-of-rows="listOfRows"></tr>
 </table>

And here's the template that gets rendered:

template: `<div>
       <tr class="main_table_tr" >
                        <td class="main_table_td column_1">999999</td>
                        <td class="main_table_td column_2">0000000001</td>
                        ... (remaining content unchanged)
                    </tr> 
 <tr class="main_table_tr" >
                        <td class="main_table_td column_1">999999</td>
                        <td class="main_table_td column_2">0000000001</td>
                        ... (remaining content unchanged)
                    </tr> 
 ... (repeated rows omitted for brevity)        
        </div>`,

https://i.sstatic.net/FlQGW.jpg

https://i.sstatic.net/FU9K6.jpg

SOLVED: After using the tbody option, the issue was resolved:

This is what is in the HTML page now:

<table class="table_body">
   <tbody is="app-skuins" :list-of-rows="listOfRows"></tbody>
</table>

And this is how it looks when rendered through the Vue component:

template: `<tbody>
        <tr class="main_table_tr" v-for="(row, index) in listOfRows">
        <td class="main_table_td column_1">{{index + 1}}</td>
        <td class="main_table_td column_2">{{row.inDoc.docNumber}}</td>
        ... (remaining content unchanged)
        </tr>        
        </tbody>`, 

Many thanks to everyone who helped!

Answer №2

It appears that there is an unnecessary div in your template - consider removing it for efficiency:

template: `
    <tr class="main_table_tr" v-for="(row, index) in listOfRows">
    <td class="main_table_td column_1">{{index + 1}}</td>
    <td class="main_table_td column_2">{{row.inDoc.docNumber}}</td>
    <td class="main_table_td column_3">{{row.sku.code}}</td>
    <td class="main_table_td column_4">{{row.sku.name}} </td>
    <td class="main_table_td column_5">{{row.serial}} </td>
    <td class="main_table_td column_6">{{row.expireDate}} </td>
    <td class="main_table_td column_7">{{row.qty}}</td>   
    <td class="main_table_td column_8">{{row.sku.unit.unit}}</td>  
    <td class="main_table_td column_9">{{row.price}}</td>  
    <td class="main_table_td column_10">{{row.vatPrice}}</td>  
    <td class="main_table_td column_11">{{row.total}}</td>  
    <td class="main_table_td column_12">{{row.vatTotal}}</td>  
    <td class="main_table_td column_13">{{row.inDoc.docDate}}</td>  
    <td class="main_table_td column_14">{{row.inDoc.contractor.name}}</td>  
    <td class="main_table_td column_15">{{row.inDoc.type.docType}}</td>  
    <td class="main_table_td column_16">{{row.inDoc.owner.fullName}}</td>         
    </tr>`,

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

The Vue component's data function is currently devoid of content

I've defined a Vue.js component as shown below: module.exports = Vue.component('folder-preview', { props: ['name', 'path', 'children', 'open'], template: `... `, methods: mapActions([ ...

What mobile browsers are compatible with the <track> element for html5 video playback?

Seeking information about web browsers that currently support the <video> tag. Are there any alternative solutions available? Can this tag be used on mobile phones, or would the text be too small to read? It seems more suitable for tablets with large ...

Is it possible to execute a function defined within an eval() function using setInterval()?

const evaluation = eval(document.getElementById("codearea").value); setInterval(evaluation, 10); I am seeking a way to access a function that is declared within the eval function, for example: setInterval(evaluation.examplefunc, 10) I attempted ...

What is the process of dynamically altering the content inside a td element?

Is there a way to dynamically change the content of a td based on the state of a checkbox? If the checkbox is unchecked, the td should remain plain, but if checked, I want the text to have a specific style: b style="font-family:Tahoma;font-size:8pt;color: ...

Node.js file successfully establishes a database connection, but script tags fail to do so

Having some trouble connecting to my MongoDB database (or MongoLab server). It works perfectly fine when the code is in the name.js file, but for some reason it fails when placed inside <script> tags within an HTML file. My folder contains only thes ...

Show side by side using javascript

My dilemma lies in having a set of cards that are meant to be displayed inline, but I have to initially hide them using "display: none". When a specific button is clicked, I aim to reveal these cards; however, upon doing so, each card seems to occupy its o ...

Modify the div's visibility based on selected option in the dropdown menu

In my PHP file, I have the following codes: <section id="placeOrder"> <h2>Place order</h2> Your details Customer Type: <select name="customerType"> <option value="">Customer Type?</option> <option value="ret ...

Tips for modifying HTML elements and navigating to a different webpage

As I delve into the world of front-end web development, I decided to challenge myself with a little exercise by creating a basic HTML form. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta ...

Effective Methods for Implementing CSS Variables within nth-child Selectors

Objective: To pass a variable successfully as a parameter to nth-child. The task is to make the third line turn green in the example provided. Dilemma: Currently, the parameter is being disregarded as a variable. Inquiry: Is achieving this possible? If s ...

Guide on how to showcase an array in a string format using table rows in JavaScript or jQuery

After making an AJAX call to a PHP database, I receive a String as a result in my script. The format of the string is shown below: array(4) { [0]=> array(3) { ["id"]=> string(3) "181" ["number"]=> ...

Patience is key as you await the element to load and smoothly render the data in vue.JS

Is there a way to ensure that the graph is only rendered and filled with data after the data has been returned from the backend? Currently, even though the data is returned, the graph appears blank. Here is my JavaScript code: methods: { refresh( ...

Guide to resolving a blank webpage issue post running 'npm run build'

I am currently in the process of working on a project that involves Vue and Firebase. Unfortunately, I have encountered an issue where my development server is no longer rendering new routes from my Vue router after building and deploying to production. F ...

Django update button to change form status

Each row in the table contains a button with the unique identifier of the element. Clicking on the button will populate the form with the corresponding data. I suspect that there is an issue with the renderer, as it clears the form and I'm unsure how ...

What is the best way to complete a CSS animation and load a new URL simultaneously?

I was thinking of incorporating a series of fade-ins, followed by a fade-out, and concluding with the loading of a new page (target=self). After some research online, it appears that CSS animations do not include the functionality to fetch a new URL as the ...

Adjusting Column Placement in Bootstrap Grid System

I am struggling to achieve a specific bootstrap grid system and could use some guidance. Here is the grid system I am trying to create: https://i.sstatic.net/fhEHU.jpg I have attempted to implement the grid system using the code provided in this JSFiddl ...

Unraveling the Mystery: Retrieving selectionStart and selectionEnd in Safari on iOS

We have implemented a feature on our website that allows users to save highlights of text. While this functionality is working perfectly in all other browsers, it seems to be failing in Safari on iOS as the selection is not being captured. Using Vue, here ...

Inline width being applied to elements in IE9 when display settings are set to 125% magnification

It seems that when a user adjusts their display settings to 125% from the Control Panel, IE9 will automatically add extra width inline to elements like this: <div class="container" id="main" style="width: 1500px"> <!-- Insert code here --> &l ...

Incorporating Vue.js components into PHP applications

I am currently working on a project using PHP in conjunction with Vue.js and vue-router. In my PHP form handler, I have implemented functionality to send emails. What I am trying to achieve is redirecting the user to a specific component within my Vue ap ...

Triggering the click event three times on a dynamically generated element

I am currently facing a simple issue. I am attempting to implement a click event on dynamically generated elements such as this: $(document).ready(function(){ $('ul').on('click', 'li.clickable', function() { conso ...

Ways to identify changes in an HTML page following a form redirection

views.py class UpdatePasswordView(PasswordChangeView): form_class = UpdatePasswordForm success_url = reverse_lazy("login") login.html {% if passwordChanged %} <p style="color:green;">Your password has been successfu ...