更新时间:2021-07-07 10:13:38
这样? http://jsfiddle.net/4zGvg/ 工程与任意行/ COLS。
Like this? http://jsfiddle.net/4zGvg/ Works with arbitrary rows/cols.
我们的想法:我们有值
矩阵和范围
矩阵。对跨度值
是
The idea: we have values
matrix and span
matrix. The values of span
are
0 =隐藏该单元
1 =正常细胞
X> 1 =细胞与ROWSPAN X
x > 1 = cell with rowspan x
迭代通过直接命令列,并以相反的顺序行。如果某些单元格的值等于低于它的价值,增加该小区的范围
和删除范围
下面的单元格
Iterate by columns in direct order and by rows in reverse order. If some cell's value is equal to the value below it, increase this cell's span
and delete the span
of the below cell:
for (var col = 0; col < cols; col++) {
for (var row = rows - 2; row >= 0; row--) {
if (values[row][col] == values[row + 1][col]) {
span[row][col] = span[row + 1][col] + 1;
span[row + 1][col] = 0;
}
}
}
一旦做到这一点,你可以使用范围
生成完整的表或显示/隐藏单元格并设置其属性ROWSPAN
Once this is done, you can use span
to generate the complete table or to show/hide cells and set their rowspan attributes.