yam350
yam350

Reputation: 103

Vuetify Datatable - Enable content editing on all columns

I have a datatable with hundreds of columns (and rows) and I want all of them to be edittable. The Vuetify example on https://vuetifyjs.com/en/components/data-tables (section:content editing ) shows the possibilty of making cells editable. However, doing this for hundreds of column manually is out of the question. Is there a way to make all cells editable by default?

Upvotes: 10

Views: 17426

Answers (2)

Ben
Ben

Reputation: 351

I just solved this by just iterating over my headers in the v-slot template:

        <template
          v-for="h in headers"
          v-slot:[`item.${h.value}`]="props"
        >
          <v-edit-dialog
            :key="h.value"
            :return-value.sync="props.item[h.value]"
          >
            {{ props.item[h.value] }}
            <template v-slot:input>
              <v-text-field
                v-model="props.item[h.value]"
                label="Edit"
                single-line
              ></v-text-field>
            </template>
          </v-edit-dialog>
        </template>

Here is a Codeply

Upvotes: 2

Carol Skelly
Carol Skelly

Reputation: 362430

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

Upvotes: 23

Related Questions