antd 4x
antd 4x, dataIndex,从对象格式,修改为 数组格式
https://ant.design/components/table-cn/
const colIndex = 1;
const rowIndex = 2;
const columns = [
{
title: '姓名',
dataIndex: 'name',
key: 'name',
},
{
title: '年龄',
dataIndex: 'age',
key: 'age',
},
{
title: '住址',
dataIndex: ['address', colIndex, rowIndex],
key: 'address',
},
{
title: '标签',
dataIndex: ['tags',1],
key: 'tags',
},
];
antd 3x
巧用 dataIndex处理表格,二维数据
const dataSource = [
{
key: '1',
name: '胡彦斌',
age: 32,
address: '西湖区湖底公园1号',
tags: ['nice', 'developer'],
},
{
key: '2',
name: '胡彦祖',
age: 42,
address: '西湖区湖底公园1号',
tags: ['cool', 'teacher'],
},
];
const columns = [
{
title: '姓名',
dataIndex: 'name',
key: 'name',
},
{
title: '年龄',
dataIndex: 'age',
key: 'age',
},
{
title: '住址',
dataIndex: 'address',
key: 'address',
},
{
title: '标签',
dataIndex: 'tags[1]',
key: 'tags',
},
];
如果name是个对象, name: {firstname: ‘Eagle’, lastname: ‘Luo’}
将dataIndex 改为 name.firstname 或 name.lastname来获取下一层级的数据
如果使用了唯一的 dataIndex,那么我们就不再需要给每个 column加上 key了
https://ant.design/components/table-cn/#components-table-demo-colspan-rowspan
二维数据
[
{
"rate": [ "30", "25" ],
"dataSource": [
[ 10.0, 20.0, 30.0, 50.0, 100.0 ],
[ 10.0, 20.0, 30.0, 50.0, 100.0 ]
]
},
{
"rate": [ "20%", "30%" ],
"dataSource": [
[ 10.0, 20.0, 30.0, 50.0, 100.0 ],
[ 10.0, 20.0, 30.0, 50.0, 100.0 ]
]
}
]