Reputation: 744
Don't want to migrate to v8, so looking for solution
consider I have some headers and the data looks like [{value: 1, value: 'zxv', value: 'd53'}]
So I want to match my headers with that data by index: first header match first value in an array and so on.
Any options?
Upvotes: 1
Views: 648
Reputation: 363
Does it help you?
import ReactTable from "react-table-v6";
export default function App() {
const data = [
{
name: "Tanner Linsley",
age: 26
},
{
name: "Tanner Linsley",
age: 26
},
{
name: "Tanner Linsley",
age: 26
},
{
name: "Tanner Linsley",
age: 26
}
];
const columns = [
{
Header: "Name"
},
{
Header: "Age"
}
].map((col, i) => {
col.id = `${i}`; // required when the accessor is not a string
col.accessor = (d) => Object.values(d)[i];
return col;
});
return (
<ReactTable data={data} columns={columns} />
);
}
https://codesandbox.io/s/wizardly-andras-9njtov?file=/src/App.js
This one is my adaption of your sandbox on StackBlitz:
https://stackblitz.com/edit/react-wsumxr?file=src%2FApp.js
Upvotes: 1