Derived fields not working in Table


#1

Hi everyone. Well, basically that’s my issue. I have defined a couple of derived fields to process states, counties and other codes. When I try them in a Bars visualization they render, but I can’t make them work (they never render) in the Raw Data Table visualization.

Just in case I’m leaving here the definition for one of them:

cont stateMap = {
  'AL' : 'Alabama',
  'AK' : 'Alaska',
      ...
}
const state_derived = {
  'name': 'state_derived',
  'label': 'State Derived',
  'type': 'ATTRIBUTE',
  'dependencies': ['state_code'],
  'reverse': (derived) => {
      let index = Object.values(stateMap).indexOf(derived);
      let result = Object.keys(stateMap)[index];
      return result;
  },
  'function': (code) => {
        let stateStr = stateMap[code];
        return stateMap[code] ? stateMap[code] : code;
    }
}


#2

Raw Data Table is, as the name states, for raw data. Derived fields can’t be shown there. I think there is a way however to format fields that are listed in your table, but not sure if this can be used as some kind of “derived” field.


#3

Actually, cell value formatting can be used in some cases as a derived field. Take the raw value, process it and then display:

    const formatter = {
        fields: 'ALL',
        format: function (field, value) {
            if (field === 'state_code') {
                let stateStr = stateMap[code];
                return {
                    value: `<div>${stateStr}</div>`
                }
            }
            return {}
        }
    }


#4

This is great! @lennydev, this solved my problem! Thanks.