0

I want in a row table can be edited with enable and disable parameters, if edit button action in click then one row table is enable but if save button action in click then disable. and for the default table value is disabled.

It's my code:

<el-table :data="tableData" :key="index" style="width: 100%" stripe>
        <el-table-column label="Name">
          <template slot-scope="scope">
            <el-input v-model="scope.row.name" :disabled="isEdit"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="Address">
          <template slot-scope="scope">
            <el-input v-model="scope.row.address" :disabled="isEdit"></el-input>
          </template>
        </el-table-column>
        <el-table-column>
          <template slot-scope="scope">
            <el-button type="default" @click="handleSaveRow">Save</el-button>
            <el-button type="primary" @click="handleEditRow">Edit</el-button>
          </template>
        </el-table-column>
      </el-table>

but when I click edit button all rows of columns becomes enabled.

expected: edit click can change one row of table to enable

fiddle: https://jsfiddle.net/dede402/otxahoev/

2 Answers 2

2

It's normal as you use the same boolean for all rows. You must find a way to have one boolean per row indicating the edit mode.

Here is a working solution : https://jsfiddle.net/budgw/d3fxw5wq/1/

If you want to separate your data from the UI logic (generally a good idea) you should use a computed property in order to create a list with the edited field.

Sign up to request clarification or add additional context in comments.

9 Comments

but in case, the data hasn't a field/indicated of edit.
As I said you can use a computed property that add the field to your data or maintain a second list dedicated to the edit mode and with the same length as your data : jsfiddle.net/budgw/d3fxw5wq/2
oh great, so if i get data from server with axios, how to set rowState dynamic data from server?
For instance in your success callback/promise initialize rowState like that : this.rowState = this.tableData.map(row => {edited:false})
i got an error, here my code methods: { getData() { ... axios({ method: 'GET', url: BASE_API + 'productpricetiers', headers: headers, params: this.params }) .then(response => { this.dataResponse= response.data.data this.getEditState() }) .catch(error => { console.log(error) }) }, getEditState() { this.rowState = this.pricetiersData.map(row => { edited = false }) } }`
|
1

@budgw answers is correct - i would like to add to his answer. Rather than disabling the input you can make it a readonly attribute. I think its better that way and also makes your table look cleaner.

<el-input v-model="scope.row.name" :readonly="!scope.row.edited"></el-input>

Visit https://jsfiddle.net/noted/0atjsrnw/4/ for the full code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.