1

Currently, I am using the react dashboard for frontend and cube.js for the backend. Result which I get from the backend is in the form of json and each key represents the column of my database. Resultant example:

{
  user.email:"xxx",
  user.id:"xxx",
}

Where User is my table and email is the column name. This is causing me problem while rendering the data using react-table. Is there any way I can give alias to columns and get data like this:

{
  email:"xxx",
  id:"xxx"
}
leofalmeida
  • 323
  • 1
  • 10
hiren shah
  • 33
  • 6

2 Answers2

0

in javascript you can access the value like this object["user.email"]

You said you can't use it like that in react-tables, so you're going to have to transform it into another object that the table can accept.

Something like this

var user = {
   email: object["user.email"]
}

Now you can access the newly transformed object like this.

user.email
Train
  • 3,420
  • 2
  • 29
  • 59
0

you can define your accessor as a function as the sample in npm, https://www.npmjs.com/package/react-table#example

{
    id: 'email', // Required because our accessor is not a string
    Header: 'Email',
    accessor: d => d['user.email'] // Custom value accessors!
}
duc mai
  • 1,412
  • 2
  • 10
  • 17