2

I am trying to create a table where the data can be edited directly in the cells. However, I don't understand how to do this. I am using Vue.js, Vuexy and vue-good-table 2.21.1. The data is contained in the mediaPlanData variable and is reactive. The table is successfully populating with data and can be modified. However, when I change the data in the cells, this variable does not change. I did not find in the documentation vue-good-table how to do this. Please tell me how can I achieve the desired result?

<vue-good-table
:columns="columns"
:rows="mediaPlanData"
:select-options="{
        enabled: true,
        selectOnCheckboxOnly: true, // only select when checkbox is clicked instead of the row
        selectionInfoClass: 'custom-class',
        selectionText: 'rows selected',
        clearSelectionText: 'clear',
        disableSelectInfo: true, // disable the select info panel on top
        selectAllByGroup: true, // when used in combination with a grouped table, add a checkbox in the header row to check/uncheck the entire group
        }"
@on-selected-rows-change="onRowClick"
>

<template slot="table-row" slot-scope="props">
    <span>
        <b-form-input v-model="props.row[props.column.field]"
                      type="text"
        ></b-form-input>
    </span>
</template>


</vue-good-table>

data() {
return {
    pageLength: 10,
    columns: [
        {
            label: 'Channel Code',
            field: 'channelCode',
        },
        {
            label: 'Product',
            field: 'product',
        }
    ],
    
    mediaPlanData: [] //[ {"channelCode": "P230", "product": "Test"}, {"channelCode": "P230", "product": "Test4"}, {"channelCode": "P230", "product": "Test45"}, {"channelCode": "Р230", "product": "Test2"}]
}
}
methods: {              
onRowClick(params) {
    console.log('onRowClick' + JSON.stringify(params))
    this.$toast({
        component: ToastificationContent,
        props: {
            title: `Hello user! You have clicked on row ${params.selectedRows.product}`,
            icon: 'UserIcon',
            variant: 'success',
        },
    })
}
}
Ostet
  • 175
  • 1
  • 12

1 Answers1

4

I have solved this problem. Added to b-form-input

@change="changeCell(props.row[props.column.field], props.column.field, props.row.originalIndex)"

And adden method

changeCell(changedData, column, row) {
            this.mediaPlanData[row][column] = changedData
        },
Ostet
  • 175
  • 1
  • 12