表格列相同元素合并列单元格
const mergeCells = (text: string, data: any, key: string, index: number) => {
if (data?.length !== 0) {
if (index !== 0 && text === data[index - 1][key]) {
return 0;
}
let rowSpan = 1;
for (let i = index + 1; i < data.length; i++) {
if (text !== data[i][key]) {
break;
}
rowSpan++;
}
return rowSpan;
}
};
// ... antd =》table
{
onCell: (_, index: number | undefined) => {
const obj = {
children: _.ruleParentId !== null ? _.ruleParentId : "",
attrs: { rowSpan: 0 },
};
}
obj.attrs.rowSpan = mergeCells(_.leibie, data, "leibie", index!);
return obj.attrs
}
浙公网安备 33010602011771号