Lock the "tr" element dynamically at the bottom of the table

Is there a way to keep a specific tr at the bottom of a table using VUE or Js?

I have a Vue component that dynamically adds table rows based on an API call. However, I need a specific tr to always be at the bottom, and whenever a new tr is added, it should appear above the last one.

I don't want it in the tfoot section because there is other information there.

Below is the Vue component code:

<tbody>
      <tr is="deliverytable"
       v-for="delivery in deliveries"
       v-bind:key="delivery.id"
       v-bind:delivery="delivery"></tr>
</tbody>

Here is the template of the Vue component:

<tr id="data" :class="{'incomplete' : delivery.event == '4'}">
  <td>
     <div v-if="delivery.is_printable">
       <input name="deliverynote" :value="delivery.id" :checked="delivery.is_printable_by_default" type="checkbox">
     </div>
  </td>
  <td>[[ delivery.dispatched ]] Uhr</td>
  <td>[[ delivery.action ]]</td>
  <td>
    <div v-if="!delivery.is_deletable">[[ delivery.article_name ]]</div>
    <div v-else-if="delivery.event != 0" v-on:change.close="autosave($event, delivery.id)" ref="article" v-html="delivery.articleform"></div>
  </td>
  <td>
    <div v-if="!delivery.is_deletable">[[ delivery.amount ]]</div>
    <div v-else-if="delivery.event != 0" @change="autosave($event, delivery.id)" ref="amount" v-html="delivery.amountform"></div>
  </td>
  <td><div id="weight" ref="delivery">[[delivery.weight]]</div></td>
  <td class="d-none"><input type="text" name="delivery" id="id_delivery" :value="delivery.id">[[delivery.id]]</td>
  <td id="price" ref="price">[[ delivery.price ]]</td><td v-else>0.00 €</td>
  <td>
    <a v-if="delivery.is_deletable" type="button" @click="removeDelivery(delivery.id)" class="icon icon-trash-can"></a>
  </td>
</tr>

Answer №1

If you're looping through components, you can display this particular item after the loop finishes.

<table>
  <thead>
    <!-- some headers -->
  </thead>
  <tbody>
    <tr v-for="(rowItem, key, index) in dataTable" :key="index">
      <!-- your API call items -->
    </tr>
    <tr>
      <!-- your specific item -->
    </tr>
  </tbody>
</table>

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

Quarterly Date Selection Tool with jQuery

I attempted to utilize the Quarter datepicker from: http://jsfiddle.net/4mwk0d5L/1/ Every time I execute the code, I encounter this problem: Cannot set property 'qtrs' of undefined. I copied exactly what was in the jsfiddle, and included the sam ...

The expression req.files consistently comes back as an empty [object]

I have been encountering an issue with saving uploaded files using their original names (with express-fileupload). Whenever I upload a file, it gets saved in the directory as [object Object]. Node: var express = require('express') var app = exp ...

What is the most effective way to save numerical information to a file?

Imagine a scenario where there is an array filled with one million random numbers: [ 0.17309080497872764, 0.7861753816498267, ...] The task at hand is to store these numbers onto a disk for future retrieval. While storing them in text formats like JSON or ...

Conceal the heading 4 element when a specific text is searched

I have a search script that filters the text, but I want to hide the h4 element at the top of each ol. How can I achieve this? The issue I'm facing is that while the text gets filtered correctly, the h4 element (which should be hidden) remains visibl ...

Console warning in Next.js: "The 'style' property did not match."

Currently working on a website with Next.js, I've encountered a red color warning in the console related to the Image component from 'next/Image'. Unsure of the reason for this warning, I'm seeking to resolve it to ensure the project&ap ...

When using $emit, child events are not activated

In my VueJS 2.0 project, the parent component includes: <template> <child></child> <button @click="$emit('childEvent)"></button> </template> Meanwhile, in the child component, I have implemented the following: { ...

Session authentication mechanism designed to remain active only as long as the browser tab is open

Imagine you are developing a front-end application that utilizes a third-party API for authentication, with a successful authentication resulting in a JSON web token. What strategies would be most effective for storing this token and establishing a user s ...

Navigating Crossroadsjs Routing: A Beginner's Guide

After exploring various resources to understand how crossroads works, I stumbled upon a question on Stack Overflow that resonated with my struggles. However, despite spending hours trying to implement it, nothing seems to be working. The documentation on i ...

Changing a String into an XML Document using JavaScript

Found this interesting code snippet while browsing the jQuery examples page for Ajax: var xmlDocument = [create xml document]; $.ajax({ url: "page.php", processData: false, data: xmlDocument, success: someFunction }); ...

Guide to displaying highcharts using external json data for numerous series

Having an issue with using angularjs and highcharts with multiple series where the data is coming from an external JSON file. When trying to access the data with a for loop using data.data[i].data, it's not working properly. Can anyone offer assistanc ...

Transforming JQuery text upon selecting preloaded content with fire

When I copy the first name into the last name field, everything works fine for new names on the page. However, once a few names have been entered and the browser starts showing a history of names, the function doesn't work anymore if a pre-filled or o ...

Obtain the registration ID for Android to enable push notifications by utilizing PushSharp

I am currently utilizing the PushSharp library and have come across deviceToken in the sample code provided on this link. Could someone kindly assist me on how to obtain this deviceToken? The PushSharp sample code does not clearly explain this. apnsBrok ...

reveal one div and conceal another using Bootstrap's collapse feature

I'm not sure why it's not working. Maybe I missed some simple thing? I want to show one div when I use an icon, then hide the other div. Currently, if I click on the first icon, a div will show. But if I click on the second icon, the div will sh ...

How can we create a two-dimensional image with random dimensions using Math.random?

I am struggling to create a variety of flowers with different sizes from an Array. The issue I'm facing is that every time I click to add a new flower, it changes the size of all existing flowers as well. What I would like is for each added flower to ...

"Adding an Image to Another Image in HTML or JavaScript: A Step-by-Step

Hello there! I'm currently working on creating a status bar where I can add an image after another image. Let me explain my idea clearly. So, I have two images in GIF format: one is white and 10x10px, and the other one is black and also 10x10px. On ...

Generate new variables based on the data received from an ajax call

Suppose there is a .txt file containing some integers separated by spaces, like '22 1 3 49'. I would like to use Ajax to read the file as an array or list, and then save each integer as a JavaScript variable. Currently, this code reads all cont ...

Testing inherit from a parent class in a unit test for Angular 2

Trying to create a unit test that checks if the method from the base class is being called This is the base class: export abstract class Animal{ protected eatFood() { console.log("EAT FOOD!") } } Here is the class under test: export ...

The 'Access-Control-Allow-Origin' header is missing

I am encountering the following issue: XMLHttpRequest is unable to load http://localhost:8000/scripts/advaced_donwload/advancedUpload/vueupload/store.php. The requested resource lacks the 'Access-Control-Allow-Origin' header. As a result, ...

Utilizing React Classes Based on Conditions

I'm attempting to add the class active if commentBadgeActive is true. The Scholar image should transition from grayscale to colored. <Paper className={classes.paper}> <div className={classes.profile}> < ...

What is the correct method for verifying the presence of a field in JavaScript (or its frameworks)?

Is there a better way to rewrite this computed method in JavaScript to handle cases where a field may not be available? computed() { isVerified() { return this.name.info.is_valid; } } I can make it less verbose, but I want it to still functi ...