Change the default width of a VuetifyJS DataTable cell

假装没事ソ 提交于 2020-07-06 06:56:14

问题


I'm using the VuetifyJS Data Table and I need to move the entries of each header cell as close as possible to each other. I tried to add a width to each header but that didn't work - it seems there is a predefined width one can't go below.

Update: This is how it should look like - the margin between each row should be fixed at 10px:

Here is a CodePen example:

https://codepen.io/anon/pen/ejEpKZ?&editors=101
 <div id="app">
  <v-app id="inspire">
    <v-data-table
      :headers="headers"
      :items="desserts"
      class="elevation-1"
    >
      <template slot="headerCell" slot-scope="props">
        <v-tooltip bottom>
          <span slot="activator">
            {{ props.header.text }}
          </span>
          <span>
            {{ props.header.text }}
          </span>
        </v-tooltip>
      </template>
      <template slot="items" slot-scope="props">
        <td>{{ props.item.name }}</td>
        <td class="text-xs-right">{{ props.item.calories }}</td>
        <td class="text-xs-right">{{ props.item.fat }}</td>
        <td class="text-xs-right">{{ props.item.carbs }}</td>
        <td class="text-xs-right">{{ props.item.protein }}</td>
        <td class="text-xs-right">{{ props.item.iron }}</td>
      </template>
    </v-data-table>
  </v-app>
</div>

How to get them close together?


回答1:


You can add another empty header and set width of every column to min value(1%), except empty to make it fill all free space. Also you need to add empty td to table body template to make grey row dividers visible.

See codepen: https://codepen.io/anon/pen/WKXwOR




回答2:


You can play with CSS, override their classes. Try modifying td's width

Here you have a code pen: https://codepen.io/anon/pen/gjxPMJ

I have also aligned text to the left for td :<td class="text-xs-left">

Just play with the width value to get what you want, you can use percentages as well.



来源:https://stackoverflow.com/questions/51527489/change-the-default-width-of-a-vuetifyjs-datatable-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!