Search code examples
javascriptreactjscube.js

Change resultant's key name in cube.js


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"
}

Solution

  • 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!
    }