When extracting information from a table within a Vue.js and Vuetify.js function

When trying to display a table, only one row is being printed. How can I resolve this issue? I have attempted various solutions (Vanilla JS worked). This project is for educational purposes and I am relatively new to JS and Vue.js.


<template>
  <v-data-table
    :headers="headers"
    :items="houses"
    class="elevation-1"
  >
    <template v-slot:items="data">
      <td class="text-xs-left">{{ data.item.name }}</td>
      <td class="text-xs-left">{{ data.item.party }}</td>
      <td class="text-xs-left">{{ data.item.state }}</td>
      <td class="text-xs-left">{{ data.item.seniority }}</td>
      <td class="text-xs-left">{{ data.item.votes }}</td>
    </template>
  </v-data-table>
</template>

This is the header:


  headers: [
    { text: 'Full Name', value: 'name' },
    { text: 'Party', value: 'party' },
    { text: 'State', value: 'state' },
    { text: 'Seniority', value: 'seniority' },
    { text: '% Votes', value: 'votes' }
  ],
  houses: [
    {
        name: getNameHouse(),
        party: getPartyHouse(),
        state: getStateHouse(),
        seniority: getSeniorityHouse(),
        votes: getVoteHouse()
    },
  ]

This is the function snippet that retrieves the party affiliation:


function getPartyHouse (){
  var JSONhouse = data_house,
  jHouseLen = JSONhouse.results[0].num_results;

  for (var i = 0; i < jHouseLen; i ++ ){
      return JSONhouse.results[0].members[i].party;
  }
}

This is just an example of the function used, with similar functions for other data retrieval tasks.

See what I see

Answer №1

Discussing my observation:

Based on my understanding, the data object 'houses' seems to be an array containing objects with a length of 1. This implies that your table will only display a single row with the provided data. To ensure all data is properly shown in the table, I suggest consolidating all relevant information before constructing the table.

To further illustrate my point, here's a sample code snippet for reference. Please note that adjustments may be necessary according to your specific input structure.

data: () => {
  return {
    headers: [{
      text: 'Full Name',
      value: 'name'
    }, {
      text: 'Party',
      value: 'party'
    }, {
      text: 'State',
      value: 'state'
    }, {
      text: 'Seniority',
      value: 'seniority'
    }, {
      text: '% Votes',
      value: 'votes'
    }],
    houses: [] // Data container to be populated later
  }
},
created: () => {
  let input = data_house.results[0].members
  
  input.forEach((member) => {
    houses.push({
      name: member.name,
      party: member.party,
      state: member.state,
      seniority: member.seniority,
      votes: member.votes,
    })
  })
}
<v-data-table :headers="headers" :items="houses" class="elevation-1">
  <template v-slot:items="data">
    <td class="text-xs-left">{{ data.item.name }}</td>
    <td class="text-xs-left">{{ data.item.party }}</td>
    <td class="text-xs-left">{{ data.item.state }}</td>
    <td class="text-xs-left">{{ data.item.seniority }}</td>
    <td class="text-xs-left">{{ data.item.votes }}</td>
  </template>
</v-data-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

Autocomplete with Avatar feature in Material UI TextField

Is it possible to display an avatar in the text field of the autocomplete material-ui component when using the getOptionLabel prop, which only accepts a string? The expected UI shows a profile picture and name for each option. Can we achieve the same thi ...

What causes the "node: bad option" error to occur when I include a custom flag in the nodejs command line within an Angular 9 application?

Seeking assistance with adding a custom flag to the npm start command in an Angular 9 project. The goal is to intercept proxy requests within the local server and manipulate data. However, encountering the "node: bad option" error consistently. Looking for ...

Django CSS graphical interface for selecting styles

I am looking to implement a feature that allows users to select an "interface theme": To enable users to change the theme across all templates, I have created a dropdown in my base.html. For all my HTML templates, I utilize a base.html file by extending ...

Guide to sending an array to a Node.js web service using AngularJS

Attempting to add an array of data to a Node.js web service using the code below. $scope.addList = function(task,subtask){ subtask.checked= !(subtask.checked); var data = { "taskId": task._id, "subTaskName": subtask.subTaskNa ...

React encountered an unexpected termination of JSON input during parsing

Upon running npm install, I encountered an error that is shown in the following link: https://i.stack.imgur.com/nVvps.jpg This issue has been causing trouble for me today and I'm unsure of the reason behind it. ...

Is there a way to locate a null string within this data arrangement?

I am looking to create functionality where, when a button is clicked, the application checks the state and takes different actions based on the result. Specifically, I want to ensure that there are no empty "value" fields, and if there are, redirect to ano ...

Utilizing ReactJS useState to eliminate a className

Basically, I'm trying to remove a className from an element when a button is clicked. I've attempted to use useState hooks and a regular function, with the onClick event on the button triggering this function/setUseState. However, the className l ...

When refreshing the page, redux-persist clears the state

I have integrated redux-persist into my Next.js project. The issue I am facing is that the state is getting saved in localStorage when the store is updated, but it gets reset every time the page changes. I suspect the problem lies within one of the reducer ...

What is the purpose of using @ViewChild to access a component's function from another component?

During a discussion with my tutor, I learned that in Angular we can utilize functions defined in any service by simply importing the service. However, unlike services, components cannot be directly imported into other components. To access a function from ...

The overlay background on the image does not seem to be functioning correctly

I'm currently working on adding an overlay to my image in order to darken it and display text over the top. I've tried using absolute positioning for both the image and overlay, but the overlay ends up covering the entire window and sitting above ...

Directive unable to recognize ng-pattern functionality

I am attempting to encapsulate an <input> within a directive in order to manage date validation, conversion from string to Date object, and keep the Date version in the original scope. The functionality seems to be working as intended. However, the n ...

Making an Ajax request to retrieve progress information by utilizing IProgress

I have encountered an issue with my code involving 2 ajax API calls. One call fetches data through a lengthy process, while the other retrieves progress values using the IProgress interface and runs every 5 seconds. The value from ReportProgress successf ...

Error in Nuxt JS / Vue JS search feature functionality

Recently, I received assistance with creating a search feature for a real estate website. The concept is to have a /properties page showing a list of properties along with a universal search component on every page. This component has an action that direct ...

I attempted to pull information from the database and display it in my checkboxes. However, I encountered an issue where I am unable to save the selected checkboxes back to the database

This code snippet is written in Blade for a reservation form: <div class="col-lg-6"> <div class="contact-form"> <form id="contact" action="{{url('/reservatio ...

Ways to create a clickable red button

I'm working with bootstrap, CSS, and particle.js for this project. I have also linked a custom CSS file here. However, when I apply bootstrap and particle.js, the red color generate password button becomes unclickable. After checking in Chrome dev too ...

What are some ways to bypass a closed Google form that is no longer accepting responses? I need to find a way to submit my form even after the deadline

Is there a way to trick a closed Google form that says it is "no longer accepting responses"? I'm looking to submit a form past the deadline. Is there a method to access and submit a form that has already been closed? The code for the closed form appe ...

What steps should I take to address both the issue of duplicate names and the malfunctioning fixtures?

There are issues with duplicate item names and the cache not updating immediately after running the script. Instead of fetching new data, it retrieves previous values from the last item shop sections. If the remove_duplicates function is not used, it displ ...

Tips for transferring an array variable into a div element using AJAX

I have a div like the following: <div id="#myid"> if($values){ echo "<p>$values['one']</p>"; echo "<p>$values['two']</p>"; } </div> Due to the large size of my div, I want to make a request ...

Which event in the listbox should I trigger to adjust the scroll position?

My webpage includes a listbox inside an update panel. I've managed to capture the scroll position, but now I'm facing difficulty in identifying the right javascript event to call my function for setting the scroll position after the update panel ...

What is the best way to utilize Content-Disposition: attachment?

I am new to creating websites and I am trying to make it easier for users to download mp3's from my site by allowing them to left click instead of the traditional right click and save as method. In order to achieve this, I need to set the Content-Disp ...