cscan / vue-excel-editor

Vue2 plugin for displaying and editing the array-of-object in Excel style
MIT License
555 stars 108 forks source link

Header Label not updating #22

Closed Akhilskt closed 4 years ago

Akhilskt commented 4 years ago

I am new to this Plugin. I could not update(two waybinding) the header label in JSON. Basically what i want is i just give a blank excel sheet for uset to enter and change values as per his needs.So i am loading a blank excel sheet with two rows just like

<vue-excel-editor v-model="defaultJson" > <vue-excel-column v-for="(col,index) in defaultJson" :key="index" :field="'col' + (index+1)" :label="'col' + (index+1)"/> </vue-excel-editor>

defaultJson:[ {col1:'',col2:''}, {col1:'',col2:''}, ],

So the excel sheet is loaded with header labels col1 and col2. Now if i update/edit col with anything it is showing up in UI. But defaultJson object still shows the header as col1 and col2 only with values entered in rows([{col1:'asf',col2:'ads'},{col1:'asf',col2:'ads'}])

Whenever I change the header column label the defaultJson also should update keys with new labels.

I may be missing something. Could not figure it out.

cscan commented 4 years ago

I obtain the vue-excel-column info only during start and never read again. If you want a dynamic column label, you can provide a method to prop header-label, something like this:

<vue-excel-editor :header-label="dynamicLabel">
...
</vue-excel-editor>
methods: {
   dynamicLabel (label) {
      switch (label) {
         case 'col1': return 'asf'; break;
         case 'col2': return 'ads'; break;
      }
   }
}
Akhilskt commented 4 years ago

By doing the above suggestion the label is getting changed but not the keys in the data object. We want the keys in the data object also to be updated when we update a column label. Is it possible? Screenshot from 2020-07-14 15-57-08 See in the above pic i changed to column label from 'col1' to 'asf' but the data object still shows as 'col1'

Akhilskt commented 4 years ago

@cscan any update on this? Any possibility of the above-mentioned scenario.

cscan commented 4 years ago

There is no simple way to do 2-way binding for the column header. If you want to remember the column header, you may try the "remember" prop which can instruct the component to save the grid header and other settings to localStorage, or listen to the "setting" event to handle the header changed by retrieving the label text from the fields argument. This is all I can help. Thanks.

Akhilskt commented 4 years ago

Okay Thanks.. Anyhow having 2-way binding for the column header is good to have. Please consider this in future enhancement tickets.