Enhancing v-data-table with an additional row in Vuetify

I am currently working on enhancing my v-data-table by adding an additional row at the end. This extra row will display a sum value, which needs to be fetched from an array provided by an API instead of being calculated on the frontend. My main question is how can I integrate the sum array into the table as an extra row at the bottom? I have a general idea of the structure needed, but I am struggling to implement it correctly. Any guidance or assistance on this matter would be greatly appreciated. Thank you!

<v-data-table>
<template v-for="s in sum">
</template>
</v-data-table>

Answer №1

Utilize the body.append slot for your convenience

Check out this modified example inspired by a sample from vuetify documentation

<div id="app">
  <v-app id="inspire">
    <v-data-table
      :headers="headers"
      :items="desserts"
      class="elevation-1"
    >
      
      <template v-slot:body.append>
        <tr>
          <td/>
          <td>{{total.calories}}</td>
          <td>{{total.fat}}</td>
          <td>{{total.carbs}}</td>
          <td>{{total.protein}}</td>
          <td/>
        </tr>
      </template>
      
    </v-data-table>
  </v-app>
</div>
new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data () {
    return {
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'start',
          value: 'name',
        },
        { text: 'Calories', value: 'calories' },
        { text: 'Fat (g)', value: 'fat' },
        { text: 'Carbs (g)', value: 'carbs' },
        { text: 'Protein (g)', value: 'protein' },
        { text: 'Iron (%)', value: 'iron' },
      ],
      desserts: [
        {
          name: 'Frozen Yogurt',
          calories: 159,
          fat: 6.0,
          carbs: 24,
          protein: 4.0,
          iron: '1%',
        },
        // .... etc
        {
          name: 'KitKat',
          calories: 518,
          fat: 26.0,
          carbs: 65,
          protein: 7,
          iron: '6%',
        },
      ],
    }
  },
  computed:{
    total(){
      const sums = {
          calories: 0,
          fat: 0,
          carbs: 0,
          protein:0,
      }
      this.desserts.forEach(({calories, fat, carbs, protein}) => {
         sums.calories += calories;
         sums.fat += fat;
         sums.carbs += carbs;
         sums.protein += protein;
      })
      return sums
    }
  }
})

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

Display a loading animation while the collapsible block is expanding in jQuery Mobile

I am experiencing an issue with displaying a loading icon when a collapsible block is opening. Within the collapsible block, there is a dynamically populated listview generated through ajax/php. This list could potentially contain up to 500 elements, so I ...

Using the onSelect/onChange event in an EJS file, link it to a JavaScript function in an external file located on

I have been searching for examples of how to call an external script in ejs for rendering dynamic variables, but so far I have not been successful. I have experimented with different placements of the code, but I always end up with the dynamic text display ...

How can I retrieve the "column" id in Draggable Vue?

Currently, I am experimenting with the draggable feature to create a kanban board with four columns. To start off, I decided to build two columns using vue-draggable. However, I am facing difficulty in accessing the specific column of a task. Here is my i ...

The Amadeus flight booking feature is running smoothly, however, the Hotel Booking API is not functioning properly

When I initially integrated Amadeus for flight booking, everything worked smoothly. However, issues arose when trying to integrate hotel bookings. When utilizing the nodejs library of Amadeus for hotel offers, an error was encountered stating that the acce ...

Vue, anticipate the Watch

My application has a similar structure when it comes to architecture. computed(){ currentValue = this.$store.currentValue; } watch() { currentValue() = async function () { //perform asynchronous action } }, methods: { updateValue( ...

Encounter Unspecified Variable Within app.get(...)

Express Enigma After setting the variables const username = "a" const password = "a" I attempted to reassign them using {username, password} = req.body (This was within a form on /createaccount) However, I encountered an er ...

Tips on retrieving and sending an XML string in PHP to JavaScript using MySQL

Here is the code snippet I have: <input type='button' value='clickme' onclick='download(\"\" . $rowtable['Protocolo'] . \".xml\", \"\" . $rowtable['XML&a ...

Ways to pause for the completion of multiple HTTP promises and display a modal exclusively when all promises result in failure

There are two separate HTTP calls on a page that need to be handled independently. vm.$onInit = function() { .... .... //Retrieve all items during initialization ds.getAllItems().then(function(result){ vm.items = result; },funct ...

Utilizing JavaScript to trigger an email with PHP variables included

i am trying to pass a few php variables using a javascript trigger. Everything seems to be working with the variables, databases, and script but I am struggling with the PHP part. Here is my attempt at the PHP code, although it clearly has some issues. I ...

Is there a way to ensure that @angular/core is utilizing the most up-to-date version of zone.js in its peerDependencies configuration?

This code passes the test, but there is an issue: it('should successfully retrieve data when getDownloadProgress() is called', (done: DoneFn) => { let response = { 'process': {}, 'success': 'success ...

Blog Writer: Picture quality compromised when adjusting size

Issue with blurry images after resizing. The problem is noticeable in the three main images located under the Header section. To preview the blog, click on this link: Click Here Your assistance in solving this issue would be greatly appreciated. Thank yo ...

Aligning checkboxes in Vue.js: Centering checkboxes inside table cells

Having trouble with aligning checkboxes in a Vue.js application. I want them centered within their table cells, but they keep aligning to the left. When I apply CSS styling to center them, they all unexpectedly align vertically to the leftmost column of th ...

Is there a way to access the dimensions of a Bootstrap 4 popover?

I'm attempting to dynamically retrieve the height/width of the Bootstrap popover. I have the context in which I'm trying to grab the height/width: console.log(context); console.log(context.getBoundingClientRect().height); console.log(context.get ...

Element appearing on screen but not found in the document structure

While using Selenium for HCI tests, I encountered a situation where Selenium was unable to locate a visible element. After some investigation, it seems that the element is visible but not present in the DOM. I could be wrong, but that’s how it appea ...

What is the best way to pass the value of a selected option to an express server

<label for="exampleFormControlSelect1"> <strong>Please Select the Number of PDFs to Merge:</strong> </label> <select class="form-control" id="exampleFormControlSelect1"> <option name=" ...

Failure to Trigger AJAX Success Callback Function

I am currently working on a basic website using Python and JavaScript. I am attempting to invoke a method from the client side and receive a response, but unfortunately, the success function does not seem to execute no matter what I try. Below is my JavaS ...

I'm attempting to save JSON data values in an array through the servlet, but I keep encountering the error "posts.map is not a function"

import React, { Component } from "react" import axios from "axios" import { List } from "@material-ui/core" class PostList extends Component { constructor(props) { super(props) this.state = { posts: [] ...

Is there a way to only print a single integer within a for loop in JavaScript without displaying the entire array's values?

Here is the issue that needs to be addressed: The task is to find a number greater than 15 from a list of numbers. If no number meets this criteria, print -1. Input Description: 0<n<100 Input consists of a number n followed by n numbers on separate ...

Having trouble with jQuery not recognizing onclick events on dynamic ids?

I've created a dropdown that generates dynamic IDs when 'add' is clicked, such as option-1, option-2. However, I'm facing issues with implementing an onclick action on these dynamically generated IDs. I require the onclick action to be ...

Creating a tooltip using only Javascript (displaying/dismissing on click)

I am searching for JavaScript plugins, without using jQuery, that will help me create a basic tooltip feature. What I want is to be able to click on an image and have a div appear below the image with some text inside along with a triangle in one corner. ...