Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a vuetify data table to span the entire width of a container when it is inside a card?

I have a Vuetify data table that is nested inside a v-card so that I can enable an inline search on the data table, but this is causing it to shrink down and only take up a small amount of the overall container whereas it was filling the entire container when not nested in the v-card.

I have reproduced a minimal example of this on codepen at https://codepen.io/bigtunacan/project/editor/XGRpVL

The main area of concern though is here.

      <v-list-tile @click="">
        <v-list-tile-action>
          <v-icon>dashboard</v-icon>
        </v-list-tile-action>
        <v-list-tile-content>
          <v-list-tile-title>Dashboard</v-list-tile-title>
        </v-list-tile-content>
      </v-list-tile>

      <v-list-tile @click="">
        <v-list-tile-action>
          <v-icon>settings</v-icon>
        </v-list-tile-action>
        <v-list-tile-content>
          <v-list-tile-title>Settings</v-list-tile-title>
        </v-list-tile-content>
      </v-list-tile>

    </v-list>
  </v-navigation-drawer>

  <v-toolbar app fixed clipped-left>
    <v-toolbar-side-icon @click.stop="drawer = !drawer"></v-toolbar-side-icon>
    <v-toolbar-title>Candy Bars</v-toolbar-title>
  </v-toolbar>

  <v-content>
    <v-container fluid fill-height>

    <template>
      <v-card>
        <v-card-title>
          Routes
          <v-spacer></v-spacer>
          <v-text-field append-icon="search" label="Search" single-line hide-details v-model="search"></v-text-field>
        </v-card-title>
        <v-data-table v-bind:headers="headers" :items="routes" :search="search" hide-actions class="elevation-1">
          <template slot="items" slot-scope="props">
            <td><router-link :to="{ name: 'route', params: {id: props.item.id}}">{{ props.item.name }}</router-link></td>
            <td>{{ props.item.agency }}</td>
          </template>
        </v-data-table>
      </v-card>
    </template>

    </v-container>
  </v-content>

  <v-footer app fixed>
    <span>&copy; 2017</span>
  </v-footer>

</v-app>    
like image 322
bigtunacan Avatar asked Nov 16 '17 03:11

bigtunacan


People also ask

What does V spacer do?

v-spacer is a basic yet versatile spacing component used to distribute remaining width in-between a parents child components. When placing a single v-spacer before or after the child components, the components will push to the right and left of its container.

What is V flex in Vuetify?

Vuetify Flex Align Content. Vuetify provides flex align content classes that we can use to set the align-content CSS property of the flex container. The align-content modifies the flexbox items on the x-axis or y-axis for a flex-direction of row or column respectively.

How do you use Vuetify V slots?

Vue slots syntax with v-slot directive – combine the slot and the scoped slot in a single directive. You can see that: – We use <template v-slot:header> to wrap <p> tag instead of <p slot="header"> directly. This is because Vue v-slot can only be used in <component> or <template> html tag.

Is Vuetify responsive?

With the VuetifyJs grid system, you can create very powerful responsive layouts without any line of JavaScript code.


1 Answers

Instead of the <template>, wrap the card in a <v-layout child-flex> like so:

...
<v-content>
  <v-container fluid fill-height>

    <v-layout child-flex>
      <v-card>
        <v-card-title>
          ...

child-flex is a class that gives its children (in this case just the card) the css rule flex: 1 1 auto, making them grow to fill available space.

like image 116
Kael Watts-Deuchar Avatar answered Sep 19 '22 01:09

Kael Watts-Deuchar