当前位置:网站首页>table 组件指定列合并行方法
table 组件指定列合并行方法
2022-07-02 06:22:00 【秦时明月之安康】
大多数table组件只提供了一个合并行或者合并列的抽象方法,例如 element ui 组件,
该方法的参数解释及其用法如下,
看得出来,rowspan代表每一行数据实际占用的行数,colspan代表每一行数据实际占用的列数,我们可以基于原始数据封装如下方法,
export const getSpanMethodData = (data = [], columns = [ ]) => {
let mergeColumns = {
} // 用来记住合并列时数据的索引和重复的次数
let pos = {
} // 用来记录需要合并的列每次出现重复时,重复的次数
columns.forEach(p => {
mergeColumns[p] = []
pos[p] = 0
})
for (let i = 0; i < data.length; i++) {
if (i === 0) {
columns.forEach(p => {
mergeColumns[p].push(1)
pos[p] = 0
})
} else {
columns.forEach((p, index) => {
let obj = {
curr: '',
prev: '',
}
for (let j = 0; j <= index; j++) {
obj.curr += JSON.stringify(data[i][columns[j]])
obj.prev += JSON.stringify(data[i - 1][columns[j]])
}
if (obj.curr === obj.prev) {
mergeColumns[p][pos[p]] += 1
mergeColumns[p].push(0)
} else {
mergeColumns[p].push(1)
pos[p] = i
}
})
}
}
return mergeColumns
}
当执行span-method方法的时候,就可以这样写,
handleSpan ({
row, column, rowIndex, columnIndex, }) {
if (columnIndex === 0) {
const _row = this.table.spanArr[column.key][rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col,
}
}
},
边栏推荐
- CUDA中的Warp Shuffle
- pytest(1) 用例收集规则
- CUDA and Direct3D consistency
- Code skills - Controller Parameter annotation @requestparam
- Dynamic global memory allocation and operation in CUDA
- Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)
- Redis——缓存击穿、穿透、雪崩
- 最新CUDA环境配置(Win10 + CUDA 11.6 + VS2019)
- Latex在VSCODE中编译中文,使用中文路径问题解决
- Sentinel Alibaba open source traffic protection component
猜你喜欢
FE - 微信小程序 - 蓝牙 BLE 开发调研与使用
PgSQL学习笔记
ctf三计
Solution to the black screen of win computer screenshot
Redis - grande question clé
js中map和forEach的用法
Blog directory of zzq -- updated on 20210601
Latex在VSCODE中编译中文,使用中文路径问题解决
Sentinel Alibaba open source traffic protection component
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
随机推荐
CUDA与Direct3D 一致性
automation - Jenkins pipline 执行 nodejs 命令时,提示 node: command not found
Kotlin - verify whether the time format is yyyy MM DD hh:mm:ss
Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu
计算属性普通函数写法 和 set get 写法
Hydration failed because the initial UI does not match what was rendered on the server. One of the reasons for the problem
实现strStr() II
Eggjs -typeorm 之 TreeEntity 实战
AWD学习
virtualenv和pipenv安装
There are multiple good constructors and room will problem
MySql索引
Vector types and variables built in CUDA
(the 100th blog) written at the end of the second year of doctor's degree -20200818
VSCODE 安装LATEX环境,参数配置,常见问题解决
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
Code skills - Controller Parameter annotation @requestparam
记录一次RDS故障排除--RDS容量徒增
20201002 VS 2019 QT5.14 开发的程序打包
Dynamic global memory allocation and operation in CUDA