Home > Mobile >  Is it possible to modify one particular column in v-data-table header
Is it possible to modify one particular column in v-data-table header

Time:01-30

I want to modify one column header and add a check box. I used the code below to add a check box. But I had to specify each column and add the checkbox manually.

```https://codepen.io/SanuSanal/pen/WNKzVJP?editors=1111```

This overrides the default styling of the table. I need to know whether there is any way to add a check box to the table header without changing the default properties of the table header.

I am new to Vue.Js. Can someone please help?

CodePudding user response:

I think you are looking for the header.<name> slot. Similarly, the item.<name> slot is used to override the default rendering of a specific cell.

Note that you should always use different values in your header data definition, as that data is used as key in v-for:

headers: [
  { text: 'Column 1', value: 'foo' },
  { text: 'Column 2', value: 'bar' },
  { text: 'Checkbox Column', value: 'myCheckbox' }
],
<v-data-table :items="items" :headers="headers">
  <template v-slot:header.myCheckbox="{ header }">
    {{ header.text }}
    <v-checkbox
      v-model="selectAllSk"
      @input="selectAllSkChanged"
    />
  </template>
  <template v-slot:item.myCheckbox="{ item, value }">
    {{item[value]}}
    <v-checkbox
      v-model="selectAllSk"
      @input="selectAllSkChanged"
    />
  </template>
</v-data-table>

Also have a look at Vuetify's default row selection mechanism, which would draw the select boxes for you.

  • Related