Vuetify: card with 2 rows displayed

I attempted to add a new row to house my table component, with the intention of it occupying the entire row

Here is what I tried:

<v-col cols="12">
    <Table />
</v-col>

However, the table alignment is off

https://i.sstatic.net/HmDUy.png

The goal is to have 2 rows within a card design

  • First row (icon) + title & subtitle
  • Second row with the table

https://i.sstatic.net/f9aJJ.png

<template>
    <v-container fluid class="my-5">
        <v-row>
            <v-col cols="12">
                <v-card elevation="2" class="d-flex">
                    <!-- Icon -->
                    <v-col cols="1">
                        <v-card-title>
                            <v-btn text color="black">
                                <v-icon left x-large>{{ icon }}</v-icon>
                            </v-btn>
                        </v-card-title>
                    </v-col>

                    <!-- Title & Subtitle -->
                    <v-col cols="11">
                        <v-card-title>
                            {{ title }}
                        </v-card-title>
                        <v-card-subtitle style="color: #757575"> {{ subtitle }} </v-card-subtitle>

                        <Table />
                    </v-col>
                </v-card>
            </v-col>
        </v-row>
    </v-container>
</template>

Answer №1

The v-card component in Vuetify has multiple sections:

<v-card>
  <v-card-title></v-card-title>
  <v-card-subtitle></v-card-subtitle>
  <v-card-text></v-card-text> <!-- This is where you can place your table content -->
  <v-card-actions></v-card-actions>
</v-card>

Check out an example implementation of this concept here: https://codepen.io/jssDev-/pen/YzrVZjJ

Answer №2

You need to either create a grid inside each the card's children and use offset (example below) or create a grid inside the v-card and nest the card children in the second column that has width col-11 (not recommended as it goes outside the recommended card and card children nesting mentioned by @jssDev in the other answer).

<v-card elevation="2">
  <v-card-title>
    <v-row>
      <v-col class="col-1">
        <v-btn text>
          <v-icon left x-large>
            {{ icon }}
          </v-icon>
        </v-btn>
      </v-col>
      <v-col class="col-11 text-start">
        {{ title }}
      </v-col>
    </v-row>
  </v-card-title>

  <v-card-subtitle>
    <v-row>
      <v-col class="offset-1 col-11 text-start">
        {{ subtitle }}
      </v-col>
    </v-row>
  </v-card-subtitle>

  <v-card-text>
    <v-row>
      <v-col class="offset-1 col-11 text-start">
        <v-data-table :headers="[]" :items="[]" />
      </v-col>
    </v-row>
  </v-card-text>
</v-card>

Answer №3

One of the key issues to address is understanding the grid system in Vuetify.

A common best practice is to always nest a column inside a row when working with Vuetify's grid system.

Furthermore, Vuetify has its own structure for creating cards:

A v-card consists of 4 main components (which can be used multiple times each):

  • v-card-actions (contains action buttons like save or exit)
  • v-card-subtitle (provides the subtitle for the card)
  • v-card-text (the main text content of the card)
  • v-card-title (displays the title of the card)

In your specific case, you can utilize the v-card-text component to include your table, which will automatically be treated as a row containing 12 columns.

Here is an example demonstrating how to resolve your issue:

<template>
  <v-card elevation="2">
      <v-card-title>
        <!-- First row of the card --> 
        <v-row>
          <!-- First column of the row (1/12)  -->
          <v-col cols="1">
            <v-btn text color="black">
              <v-icon left x-large>mdi-link</v-icon>
            </v-btn>
          </v-col>
          <!-- Second column of the row (11/12)  -->
          <v-col cols="11">
            Title of the card
          </v-col>
        </v-row>

      </v-card-title>

    <!-- Title & Subtitle -->
      <v-card-subtitle style="color: #757575">
        <!-- Second row of the card  -->
        <v-row class="justify-end">
          <!-- Column inside the row 11/12 positioned at the end of the row using the flex class justify-end -->
          <v-col cols="11">
            Subtitle of the vcard
          </v-col>
        </v-row>
      </v-card-subtitle>

      <v-card-text>
        <v-data-table
          :headers="headers"
          :items="desserts"
          :items-per-page="5"
          class="elevation-1"
        ></v-data-table>
      </v-card-text>
  </v-card>
</template>

<script>
export default {
  name: "Hello",
  data () {
    return {
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'start',
          sortable: false,
          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: [ ... ]
    }
  },
}
</script>

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

Reveal or conceal elements with a touch of animation

I am in the process of building my own website and I've been working on implementing a button that can toggle the visibility of a specific div element. While the functionality is there, I really want to incorporate an animation to enhance it. I attem ...

Making changes to JSON format post $.get function

Struggling to make sense of the JSON properties I receive from the server. Any advice on how to change the format would be greatly appreciated. Here is a snippet of the received data: [ { "date": "2006-07-01T00:00:00.000Z", "date_processed": "2 ...

Tips on extracting data from an API using jQuery

Struggling with parsing data and feeling a bit stuck. That's why I'm reaching out for assistance. This is where I need help: How do I specifically retrieve market_cap values? Each value needs to be accessed individually for a specific string I ...

What is the best way to incorporate flags in a nodejs application when using npm run-script?

I have a NodeJS file that I execute using an "npm" command. I've been attempting to display all arguments (including flags). When the file is executed by directly calling the node executable, it functions correctly. However, when I use the npm command ...

Discover the easy way to provide a hyperlink for every row within a Bootstrap-vue table

I am working on a project that includes a table from bootstrap-vue. I am trying to add a link to each row, similar to the code snippet below: <template #row> <div @click="goToPage"> {{ item.name}} </div> </template> ...

What is the best way to clear the markers in monaco editor once the data has been validated?

I utilized setModelMarkers to add error markers on content validation of a YAML file in the Monaco Editor. However, how can these error markers be removed if the data becomes valid? monaco.editor.onDidCreateModel(function(model) { function validate() { ...

"Sortable elements in Getuikit 3 do not trigger the 'on moved' event

I'm facing an issue where I am unable to execute any actions after the sortable elements have been moved. The event 'moved' triggered by UIkit.util.on('#sortable', function (item) {}); seems to be not working as expected. The appl ...

How to designate a try / catch block as asynchronous in TypeScript / JavaScript?

I am facing an issue where the code is not entering the catch block in case of an error, try { this.doSomething(); } catch (error) { console.error(error); } This problem occurs when "doSomething" returns a promise or runs asynchronous code. doSome ...

JavaScript keydown events seem to exhibit an unusual one-second delay in triggering subsequent events after the initial event

I'm currently working on implementing character movement within a scene using Vue.js. For this purpose, I have set up key bindings for both left and right buttons: created () { window.addEventListener('keyup', this.keyup) window.a ...

Despite correctly declaring jquery-ui.js and numeric.js, the jQuery datepicker and numeric plugins are not working as expected

element, it's strange that I am not receiving any error messages. However, despite this, the jquery datepicker function and numeric plugin are not working on the intended input fields they are supposed to be linked to. This particular page is a simpl ...

Display a loading spinner by utilizing a helper function with the React context API

I'm still learning about the React Context API and I've run into an issue. I'm trying to implement a loader that starts when I make an API call and stops once the call is complete. However, when I try to dispatch actions from a helper functi ...

I'm looking for guidance on how to properly implement onChange in this particular script. Any help with the correct syntax

Can someone help me with the correct syntax for writing onChange in this script? I want to integrate these phpcode into my script. Here is the Javascript code: ih+='<div class="form-group drop_bottom" id="select_one_'+extra_num+'">< ...

Mastering MaterializeCSS: Creating a Toggle Feature for Two Notifications with a Single Button Click

Visit my Personal Website at this Link StyleSource-Library BETA While I was working on some content, I created a Container Enabler/Disabler Button. This button is positioned in the Navigation Bar on the top right and works perfectly by adding a container ...

Uncovering data with the power of jQuery: Metadata

Hey there! I have a bunch of divs similar to this: <div class="card {toggle:'A'}"> <div class="card {toggle:'B'}"> <div class="card {toggle:'C'}"> <div class="card {toggle:'D'}"> Right now, ...

"Make your slides smooth and responsive with the unslick option in slick

Currently implementing the Slick Slider on a WordPress website. The slider is designed to display 3 columns at a screen size of 1024px and above. When the screen size drops below 1024px, the slider adjusts to show 2 columns, and on mobile devices, it swit ...

How can you use jQuery to add a select element dynamically and then clear the selected choice?

Trying to build a dynamic form in the Play Framework, but my javascript skills are lacking. I found this jQuery example for adding fields dynamically, but I want to add both a text field and a select box each time. My attempt involves using this answer ...

Error encountered when attempting to have multiple chrome.runtime.onMessage listeners - port disconnection issue

I am currently developing a chrome-extension that utilizes the Dexie indexedDB Wrapper, various jQuery Libraries, and syncfusion's eGrid to manage and display data. While I know this issue has been addressed multiple times in the past, I have encounte ...

Manipulating rows [using an input field] within a table

As someone new to JavaScript, I tried my hand at coding the following piece after tweaking a tutorial I stumbled upon. The aim was to have rows with input fields added and removed within a table, but unfortunately, nothing happens when running the code. ...

Styling HTML elements for Google custom search API json results: Best practices

I have been working with the Google Custom Search API to retrieve JSON callback results for my project. I have been experimenting with the JSON callback variables based on the recommendations from Google's documentation available here: https://github ...

Tips for using a string as a generic type in TypeScript

Looking to create a flexible type that can transform existing types into ones that align with a specific API response structure. My goal is to take a variety of types and generate new types based on them, constructed as follows: // original type definition ...