I have a table that is dynamically being rendered with data in a readonly input box in each cell. In the first cell, there is an edit button. When the user clicks edit, the readonly on the input boxes should be disabled so data can be entered in each cell. The edit button should be hidden and the save button should show. When the user clicks save, it should call a method that can use the data (save to a database or something).
I thought I could use the event and drill down to the target but it's an array and I'm not sure what to do. Any ideas?
<div id="app">
<table border=1 width=100%>
<tr>
<td width=10px>EDIT</td>
<td>Program</td>
<td>Company</td>
<td>Funding</td>
<td>Funded</td>
<td>Recruit</td>
</tr>
<tr v-for="program in programs">
<td><button class="show" v-on:click="editItem($event)">edit</button> <button class="hide">save</button></td>
<td><input type="text" v-bind:data-id="program.id" readonly="readonly" v-model="program.program"></td>
<td><input type="text" v-bind:data-id="program.id" readonly="readonly" v-model="program.company"></td>
<td><input type="text" v-bind:data-id="program.id" readonly="readonly" v-model="program.funding"></td>
<td><input type="text" v-bind:data-id="program.id" readonly="readonly" v-model="program.funded"></td>
<td><input type="text" v-bind:data-id="program.id" readonly="readonly" v-model="program.Recruit"></td>
</tr>
</table>
</div>
new Vue({
el:"#app",
data() {
return {
test:"hello",
programs:"",
hide:true
}
},
created: function(){
this.getPrograms();
},
mounted: function(){
},
methods: {
getPrograms: function(){
axios.get("https://my-json-server.typicode.com/isogunro/jsondb/Programs").then((response) => {
this.programs = response.data;
})
.catch(function (error) {
console.log(error);
});
},
editItem: function(e){
console.log(e)
//console.log(e.target.parentElement.parentNode.parentElement.HTMLCollection) doesn't work
alert("Make line item editable for editing and then saving")
}
}
})
Here's the pen for reference