且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Vuetify 数据表 - 在所有列上启用内容编辑

更新时间:2023-12-01 11:02:04

AFAIK,默认情况下无法使 所有 标题字段可编辑,但您可以自定义主体模板,并动态呈现数据使用 v-for 和 v-edit-dialog 为每个项目.例如...

AFAIK, there's no way to make all header fields editable by default, but you could customize the body template, and dynamically render the data using v-for and the v-edit-dialog for each item. For example...

           <template v-slot:body="{ items, headers }">
                <tbody>
                    <tr v-for="(item,idx,k) in items" :key="idx">
                        <td v-for="(header,key) in headers" :key="key">
                            <v-edit-dialog
                              :return-value.sync="item[header.value]"
                              @save="save"
                              @cancel="cancel"
                              @open="open"
                              @close="close"
                            > {{item[header.value]}}
                              <template v-slot:input>
                                <v-text-field
                                  v-model="item[header.value]"
                                  label="Edit"
                                  single-line
                                ></v-text-field>
                              </template>
                            </v-edit-dialog>
                        </td>
                    </tr>
                </tbody>
            </template>

Codeply