New to vue and so far I'm loving it. Basically trying use BV tables to create a excel like table layout. When I click on the cell text, I want it to be replaced with an input box and revert back to text on blur. Sorting doesn't work on input fields, from what I understand, so hiding seemed like the best option.
This code technically works (duno how to get to actually run in SO's code editor), but I'm trying not to have a isHidden field for each field. Currently I would need isHiddenStartTime and isHiddenEndTime plus 1 for every other field. Considering only 1 should need the flag at a time, it seems messy.
new Vue({
el: "#app",
data() {
return {
fields: [
{
key: 'startTime',
sortable: true
},
{
key: 'endTime',
sortable: true
}
],
port: [
{
"portNumber": 1,
"startTime": "00:00:00.00",
"endTime": "21:59:59.01",
"isHidden": false,
"hiddenType": ""
},
{
"portNumber": 7,
"startTime": "00:00:00.00",
"endTime": "22:59:59.00",
"isHidden": false,
"hiddenType": ""
}
]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js"></script>
<script src="https://unpkg.com/bootstrap-vue@2.5.0/dist/bootstrap-vue.js"></script>
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css" />
<div id="app">
<b-table :items="port" :fields="fields" striped fixed responsive="sm">
<template v-slot:cell(endTime)="{ item }">
<div v-if="!item.isHidden" @click="item.isHidden = true">
{{ item.endTime }}
</div>
<div v-else>
<b-form-input
v-model="item.endTime"
@blur="item.isHidden = false"
placeholder="Enter end time"
autofocus
></b-form-input>
</div>
</template>
</b-table>
</div>
I tried adding a hiddenType with the name of the field added on click, but the v-if runs before the click. If I use the same flag (port.isHidden), the entire row changes. If I put the flag in the fields, the entire column changes. Considering it's a list, I don't see a correct way to use ref.
Again, new to view, all the issues make sense, I just can't find a clean way to make it work.