【问题标题】:Implementing a checkbox in v-data-table header在 v-data-table 标题中实现复选框
【发布时间】:2021-09-18 11:07:01
【问题描述】:

我有一个 v-data-table,其中有带有复选框的行。我正在尝试在表格标题中实现一个复选框,选择该复选框将选择表格行中的整个复选框。

这是我的代码:

             <v-data-table
               v-model="model"
          styles="font-size:5px;"
          :headers="headers"
          :items="items"                      
          single-select
          :items-per-page="10"
           class="elevation-1"  hide-default footer   
   
        >
           <template slot="headers" slot-scope="props">
  <tr>
  <th> <v-checkbox  :input-value="props.all"> </v-checkbox> 
  </tr>

</template>
          <template v-slot:item="row" :activator="{ on, attrs }">
              <!-- <tr @click="highlightRow(item.item, item)">  -->
         <tr>
            <td>{{ row.item.DisplayValue }}</td>
             <td>
                    <label class="form-checkbox">
                        <input type="checkbox" :value="row.item.DataValue" v-model="preselected1" >
                        <i class="form-icon"></i>
                    </label>
                </td>
        <td>
                    <label class="form-checkbox">
                        <input type="checkbox" :value="row.item.DataValue" v-model="preselected2">
                        <i class="form-icon"></i>
                    </label>
                </td>       
         </tr>
          </template>              
       
          </v-data-table>

我确实尝试了https://vuetifyjs.com/en/components/data-tables/#row-selection 的解决方案,但我想要实现的更像是:

Need checkbox in highlighted places

任何关于实现这一点的指针将不胜感激。

【问题讨论】:

  • 使用header 插槽并自己构建标题单元格。
  • @IVOGELOV 你有什么例子可以参考吗?我对 Vue 很陌生。

标签: vue.js vuetify.js v-data-table


【解决方案1】:

根据Vuetify documentation,你可以这样做:

<v-data-table
    :headers="headers"
    :items="desserts"
    class="elevation-1"
  >
    <template v-slot:header.colWithCheckbox_1="{ header }">
      {{ header.text }}
      <v-checkbox v-model="headerCheckboxes.colWithCheckbox_1" />
    </template>
  </v-data-table>

【讨论】:

    猜你喜欢
    • 2018-11-14
    • 2020-09-13
    • 1970-01-01
    • 2020-01-08
    • 1970-01-01
    • 2018-09-14
    • 2020-04-25
    • 2019-12-29
    • 2019-12-22
    相关资源
    最近更新 更多