combine blank cells in table generated with vuejs

I am attempting to display a table of students where each column represents a subject, and underneath each column are the names of the students who failed in that particular subject. The challenge I am facing is that my data is structured in rows instead of columns. Here is an example of the data for a table row:

[{"name":"dummy1","pass":true},{"name":"dummy1","pass":false},{"name":"dummy1","pass":false}]

In this scenario, there are 3 subjects and therefore the row length is 2 (containing 3 items).

If the second student's row looks like this:

[{"name":"dummy2","pass":false},{"name":"dummy2","pass":false},{"name":"dummy2","pass":false}]

What happens is that the first column starts with a blank cell because the first student passed the first subject, and the name for that column will only appear in the second row.

The HTML code used is as follows:

<div class="table-row" v-for="(row, i) in trows">
   <div class="item" v-for="(item, i) in row" >
      <span class="item-content" v-if="!item.pass">{{item.name}}</span>
      <span class="item-content" v-else></span>
   </div>
</div> 

My main concern is how to adjust the data so that there are no empty cells between rows when viewing it from a column perspective?

To illustrate further:

name name name        name name name
          name  == >  name name name
     name                  name name
name name name

Answer №1

If you want to specifically target failed students, one approach is to create a new computed value using the original data trows:

computed: {
    failedOnlyStudents() {
        return this.trows.map(row => row.filter(({ pass }) => !!pass));
    }
}

Afterwards, you can utilize CSS flex properties to arrange them as columns rather than rows:

<div class="table-row" style="display:flex;flex-direction:row;" v-for="(row, i) in failedOnlyStudents">
   <div class="item" v-for="(item, i) in row" >
      <span class="item-content" v-if="!item.pass">{{item.name}}</span>
      <span class="item-content" v-else></span>
   </div>
</div> 

Answer №2

It seems like what you're looking for is not exactly a traditional table, since each row doesn't hold independent meaning. Rather, it appears that you need a set of columns displayed side by side.

One approach could be to compile a list of students who have passed the first exam and present this information in a single-column table. This process can then be repeated for subsequent exams.

To generate the list for a specific exam (let's say the i-th exam), you can iterate through the student data. If the i-th element in the array indicates a pass, you can add the respective student's name to the list.

Here's some pseudo code outlining the process for the i-th exam:

examId = i
myList = []
for studentResults in studentsResultsList
  if studentResults[i]['pass']
    myList.push(studentResults[i]['name'])

You can then use a loop to create a one column table based on the values stored in myList. Additionally, you can incorporate 'i' into the loop to handle multiple exams iteratively.

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

Transforming into an input field from a dropdown with Bootstrap select when using AJAX in js.erb

I'm encountering a small issue while updating the view results via AJAX in Ruby on Rails (js.erb). Specifically, when I update/render the form using AJAX, the selectpicker transforms into a simple input and disappears from the view. Any suggestions on ...

Is JSON required to transmit an object using socket.io?

I have an object on the frontend that I want to broadcast to all connected clients. Can I send it as is, in its original form? Or do I always have to convert it into a JSON string before sending? Here is my object: var myBox = { x: 400, ...

handling forms and managing data in vue js

Hey there! I'm currently working on setting up a shopping cart in Vue.js with Laravel. I'm new to this, so I'm still learning the ropes. I have a question - Is it possible for me to bind the values from a form to the data (i.e., form value ...

Using an Ajax XML object to dynamically set images in a DataList

When making an Ajax call to retrieve an XML response and trying to set image names from the XML on a datalist, I encountered some issues. The code snippet I used for setting the image is as follows: $(".Image", tablex).attr('src', product.find( ...

Tips on handling a redirection request following a fetch post request

When communicating with my node server (Express) using fetch to build a Single Page Application (SPA), I have encountered an issue. Upon each request to the server, I validate the session and redirect to a login page if it is not valid. However, I noticed ...

Obtain the result of two "Synchronous" nested queries using Express and Mongoose

I need to fetch an array of elements structured like this: ApiResponse = [ {_id: 1, name: Mike, transactions: 5}, {_id: 2, name: Jhon, Transactions: 10} ] The user data is retrieved from a query on the "Users" schema, while the tr ...

The masonry plugin overlays images on top of each other

I have gone through similar questions but haven't found anything that applies to my specific case. Following an ajax call, I am adding li elements to a ul $.ajax({ url: 'do_load_gallery.php?load=all' }).done(function(result) { ...

Encountering CORS issue despite employing a CORS library

Encountering a CORS error while attempting to deploy my project on render using expressjs and react. The project functions smoothly on localhost, but changing the URLs to match the website results in this error: Access to XMLHttpRequest at 'https:// ...

Receive JSON data in URL as an array in PHP

What I aim to accomplish is: I have a JSON object structured like below var foo = { format:"json", type:"test", id:"26443" }; and my goal is to convert it into a URL in the following format 'http://example.com/a:3:{s:6:"format";s:4:" ...

Exploring Vue 3 and Pinia: Achieving Reactivity in Stored Values

Currently, I am working on a project using Vue 3 with the Composition API and Pinia. Within my application, I have an auth store that retrieves the default email and password values from the store. import { useAuthStore } from "stores/auth"; const authSto ...

Are the orders of events maintained when emitted using an event emitter?

I have a simple query regarding the event emitter, which is crucial for my program's logic. Currently, I am utilizing an external library that triggers events that I'm listening to. These events consist of 'data' and 'error'. ...

The conversion of a newline in an Angular page is done using &lt;br/&gt tag

Here is a function I have: setLocalVariableOnAccepted(ogp, hb, responseJson) { if (responseJson.ofgp === undefined) { this.ogpStatus = 'orange'; this.ogpStatusMsg = responseJson.ofgp + ', <br/> No change. Previous va ...

There are two distinct varieties of object arrays

I recently encountered an issue while trying to sort my array of Star Wars episodes by episode ID. The problem emerged when comparing two arrays: one manually inputted in the code snippet labeled as "1" on the screenshot, and the other generated dynamicall ...

Creating a Gulp automation task to handle ng-constant across various environments

I've been attempting to make this work, but it seems like I might be overlooking something. I'm utilizing ng-constant and configuring different environment endpoints as outlined in the ng-constants issue However, my setup involves using gulp and ...

What are the benefits of using "var self = this" for synchronizing between a class and events?

Consider this straightforward code example (it's in AngularJS for simplicity, but the scenario is common in JavaScript): angular.module('app',[]). directive('myDir', function(){ this.state = {a:1, b:2}; return { l ...

Discover the best way to retrieve attribute values using jQuery

I'm struggling to retrieve the value of the attribute "_last_val" from my input, but I'm having trouble getting it. Here is what I have attempted: demo // Here is the HTML code <form method="post" action="" id="feedback_form"> <inpu ...

Leveraging python capabilities within html documents

English is not my first language, so please excuse any spelling errors. I am working on combining HTML and Python to develop a graphical user interface (GUI) that can communicate with a bus system (specifically KNX bus). Currently, I have a Raspberry Pi ...

Setting up a div as a canvas in Three.js: Step-by-step guide

Is there a way to adjust the JavaScript in this three.js canvas example so that the scene can be contained within a specific div element on a webpage? Here is the example: https://codepen.io/PedalsUp/pen/qBqvvzR I would like to use this as the background ...

What are some ways we can enhance Map.get for react-router using ES6 Maps?

I recently implemented a map using new Map() to store my RR4 configuration within my application. My goal is to retrieve the values associated with /countries/:id when accessing /countries/1. routesMap.get('/countries/1') // should provide the ...

Using v-bind to pass props to the <nuxt> component in Nuxt.js

I recently completed a nuxt.js project where I encountered an issue with passing data to a component. In my initial Vue file, I included the following code: <nuxt v-bind:cur-language="curLanguage"/> Within a different Vue file placed in the designa ...