如果数据相同,则 html 表跨度 [英] html table span if the data is same
问题描述
我有一个 html 表格,列中有重复的数据,如下所示
I have a html table with duplicate data in the column as shown below
如果数据与下表相同,我想动态合并html表格行单元
I want to dynamically merge the html table row cell if the data is same like below table
我可以通过给出要跨越的单元格的值数量来做到这一点,但我如何动态地做到这一点
I am able to do this with giving the value number of cells to span but how can I do this dynamically
推荐答案
哇,感谢您的有趣任务.我想出了这个解决方案 http://jsfiddle.net/PhWGF/4/.不是最干净的代码,但我会把这部分留给你.
Wow, thanks for the interesting task. I came up with this solution http://jsfiddle.net/PhWGF/4/. Not the cleanest code but I will leave this part for you.
你可以把你的表想象成一个常规的二维数组
,所以这一切都归结为经典的嵌套循环.我们为同一列的每一行中的每个单元格搜索一个重复项,存储第一个和最后一个出现的位置,以便稍后确定跨度的长度.
You can think about your table as a regular 2d array
so it all comes down to the classical nested loops. We search for a duplicate for each cell in each row of the same column, store first and last occurrence to determine the length of span later.
注意,在删除重复项之前,您需要设置所有roswpan".
Note, you need to set all "roswpan" before deleting duplicates.
这篇关于如果数据相同,则 html 表跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!