ratiw / vuetable-2

data table simplify! -- datatable component for Vue 2.x. See documentation at
https://vuetable.com
MIT License
2.16k stars 399 forks source link

Normalization lost when executing method refresh #93

Closed jsonantunes closed 7 years ago

jsonantunes commented 7 years ago

Hello,

Working with a SPA application, For some reason the normalization of fields is lost when executing the refresh method, so the result of the filter is not displayed.

I added a call to the normalization method whenever loadData is executed, and it worked.

My alternate implementation to work around this problem:

`

  let self = this      
  let obj
  let normalizedFields = []
  this.fields.forEach(function(field, i) {
    if (typeof (field) === 'string') {
      obj = {
        name: field,
        title: self.setTitle(field),
        titleClass: '',
        dataClass: '',
        callback: null,
        visible: true,
      }
    } else {
      obj = {
        name: field.name,
        title: (field.title === undefined) ? self.setTitle(field.name) : field.title,
        sortField: field.sortField,
        titleClass: (field.titleClass === undefined) ? '' : field.titleClass,
        dataClass: (field.dataClass === undefined) ? '' : field.dataClass,
        callback: (field.callback === undefined) ? '' : field.callback,
        visible: (field.visible === undefined) ? true : field.visible,
      }
    }

    normalizedFields.push(obj)        
  })

  this.tableFields = normalizedFields

}`

Is this really necessary, or am I wrong somewhere?

Translated by google ;)

ratiw commented 7 years ago

@johnsoons This looks like the same issue here.

If you dynamically change fields definition, you will need to call normalizeFields, so that the fields definition is properly parsed. This can be done in Vuetable-2 by creating a ref in your <vuetable> tag like so,

  <vuetable ref="vuetable"
    //...
  ></vuetable>

Then, you can call normalizeFields like this

  this.$refs.vuetable.normalizeFields()
jsonantunes commented 7 years ago

Thanks for the @ratiw return,

It really makes sense to place them dynamically in change fields, however, in the case in question the columns fields are not changed, only the data with the filter result is changed.

ratiw commented 7 years ago

@johnsoons Sorry, I don't quite understand what you mean. Perhaps you could should me the output of the code or error messages.

jsonantunes commented 7 years ago

Hi @ratiw,

When you first get the data, everything works correctly

id Name Age
1 Janice D. Buckner 20
2 John G. Aragon 31
3 Lynn C. Whitt 40

After filtering, the data is retrieved correctly, however as normalization is lost the columns are added and the data is not listed.

--- --- ---

With the solution I mentioned, this problem in my case solved.

Thanks for listening! :)