I wanted my first columns title name to accept 2 data from my graphql query.
"rocket.rocket_name"
and "links.wikipedia"
to be displayed on the render href.
but it seems like dataIndex only accept one string.
const { Table, Divider, Tag } = antd;
const columns = [{
title: 'Name',
dataIndex: 'rocket.rocket_name',
key: 'name',
render: text => <a href="www.google.com">{text}</a>,
}, {
title: 'Description',
dataIndex: 'details',
key: 'age',
}];
const data = [
{
"id": "77",
"rocket": {
"rocket_name": "Falcon Heavy",
"rocket": {
"active": true
}
},
"links": {
"wikipedia": "https://en.wikipedia.org/wiki/Arabsat-6A"
},
"details": "SpaceX will launch Arabsat 6A to a geostationary transfer orbit from SLC-39A, KSC. The satellite is a geostationary telecommunications satellite built by Lockheed Martin for the Saudi Arabian company Arabsat. This will be the first operational flight of Falcon Heavy, and also the first Block 5 Falcon Heavy. All three cores will be new Block 5 cores. The side cores are expected to land at LZ-1 and LZ-2, and the center core is expected to land on OCISLY."
}
]
ReactDOM.render(<Table columns={columns} dataSource={data} />, mountNode);
If you want to create a cell using combined values of 2 columns, use second argument of column's render
function.
Excerpt from antd
documentation:
Here, text
is a value of column specified by dataIndex
, and record
will be the object with the row (values of all columns).
const columns = [
{
title: 'Name',
// dataIndex: 'rocket.rocket_name', // antd v3
dataIndex: ['rocket', 'rocket_name'], // antd v4
key: 'name',
render: (text, record) => <a href={record.links.wikipedia}>{text}</a>,
},
{
title: 'Description',
dataIndex: 'details',
key: 'age',
}
];
you can try this
{
title: 'İd',
dataIndex: ['id',"symbol"],
key: 'id',
render: (text,row) => <a title={row["symbol"]}>{row["id"]}</a>,
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With