react-antd-table-rowspan
Version:
react+antd表格指定的列,连续的,行合并
63 lines (58 loc) • 1.58 kB
text/typescript
interface filterItem {
name: string
symbol: any
}
/**
* antd的表格合并,需要配合rendercell使用
* @param origin 原始数组
* @param filters 条件数组,name合并的字段,symbol条件,>=,<=,=,!=
* @description symbol条件为字符串的时候是单一条件,可以是对象表示多个条件,key是字段名 value是>=,<=,=,!=
* @date 2021年9月24日09:52:19
* */
function changeData(origin: any[], filters: any[]) {
if (!Array.isArray(filters)) throw new Error('')
function mySwich(oldItem: any, newItem: any, c: filterItem) {
switch (typeof c.symbol) {
case 'string':
switch (c.symbol) {
case '=':
return oldItem[c.name] == newItem[c.name]
default:
break
}
case 'object':
let f = true
for (const key in c.symbol) {
switch (c.symbol[key]) {
case '=':
f = oldItem[key] == newItem[key]
break
default:
}
if (!f) return false
}
return true
default:
break
}
}
filters.forEach((c) => {
let index = 0
let n = 0
while (index < origin.length) {
for (let j = index; j < origin.length; j++) {
const o = origin[j]
if (mySwich(origin[index], o, c)) {
n++
} else {
break
}
origin[index][c.name + 'rowSpan'] = n
}
index += n || 1
n = 0
}
})
return origin
}
export default changeData