当前位置:网站首页>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,
}
}
},
边栏推荐
- Redis - cluster data distribution algorithm & hash slot
- After reading useful blogs
- 分布式事务 :可靠消息最终一致性方案
- 浏览器滚动加载更多实现
- Tensorrt command line program
- selenium的web自动化中常用的js-修改元素属性翻页
- Asynchronous data copy in CUDA
- CUDA user object
- Virtualenv and pipenv installation
- Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
猜你喜欢

js中对于返回Promise对象的语句如何try catch

The intern left a big hole when he ran away and made two online problems, which made me miserable

Distributed transactions: the final consistency scheme of reliable messages

ZZQ的博客目录--更新于20210601

Hydration failed because the initial UI does not match what was rendered on the server. One of the reasons for the problem

20201002 VS 2019 QT5.14 开发的程序打包

js中map和forEach的用法

PgSQL学习笔记

Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
![[literature reading and thought notes 13] unprocessing images for learned raw denoising](/img/a5/ed26a90b3edd75a37b2e5164f6b7d2.png)
[literature reading and thought notes 13] unprocessing images for learned raw denoising
随机推荐
VSCODE 安装LATEX环境,参数配置,常见问题解决
eslint配置代码自动格式化
Linux MySQL 5.6.51 Community Generic 安装教程
CUDA中的Warp matrix functions
TensorRT的命令行程序
PgSQL学习笔记
virtualenv和pipenv安装
FE - weex 开发 之 使用 weex-ui 组件与配置使用
20201025 visual studio2019 qt5.14 use of signal and slot functions
ctf三计
Redis——缓存击穿、穿透、雪崩
Data science [9]: SVD (2)
CUDA中的Warp Shuffle
Selenium+msedgedriver+edge browser installation driver pit
Eggjs -typeorm 之 TreeEntity 实战
Name six schemes to realize delayed messages at one go
ctf-web之练习赛
Sparse array (nonlinear structure)
Render minecraft scenes into real scenes using NVIDIA GPU
AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组