react合并单元格
作者:互联网
合并单元格
const mergeRows = (params, obj, index, colName,colId) => {
let arr = bookdataList.filter((item) => {
if(item.orgId == colId){
return item[colName] == params;
}
});
if (index == 0 || bookdataList[index - 1][‘orgId’] != colId) {
obj.props.rowSpan = arr.length;
} else {
obj.props.rowSpan = 0;
}
return obj;
};
//合并数组单元格
createNewArr=(data)=>{
return data.reduce((result, item) => {
//首先将fileName字段作为新数组result取出
if (result.indexOf(item.fileName) < 0) {
result.push(item.fileName)
}
return result
}, []).reduce((result, fileName) => {
//将fileName相同的数据作为新数组取出,并在其内部添加新字段rowSpan
const children = data.filter(item => item.fileName === fileName);
result = result.concat(
children.map((item, index) => ({
…item,
rowSpan: index === 0 ? children.length : 0,//将第一行数据添加rowSpan字段
}))
)
return result;
}, [])
}
标签:index,rowSpan,return,单元格,合并,fileName,react,item,result 来源: https://blog.csdn.net/wanghuaye_forlove/article/details/122586623