0
votes

how i can assign accessor name in react table if my accessor name always change so if it's just dynamic?

i have like this json coming from api.

{
        "name":"John",
        "lastname": "doe",
        "('04-29', '05-05')": 49,
        "('05-06', '05-12')": 10,
        "('05-13', '05-19')": 0,
        "('05-20', '05-26')": 50,
      },

in my react table i set my columns header and accessors like this:

  {
    Header: 'Name'
    accessor: "name",
  },

but how i can set accessors with these things?

 "('04-29', '05-05')": 49,
        "('05-06', '05-12')": 10,
        "('05-13', '05-19')": 0,
        "('05-20', '05-26')": 50,

because they are dynamic so they will change always.

1

1 Answers

0
votes

you can create dynamic columns property from your data.

const columns = data && data[0] && Object.keys(data[0]).map(accessor => ({
    Header: accessor,
    accessor
});