简体   繁体   English

html表跨度,如果数据相同

[英]html table span if the data is same

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 我想动态合并html表行单元格,如果数据相同,如下表所示

在此输入图像描述

I am able to do this with giving the value number of cells to span but how can I do this dynamically 我可以通过给出跨越单元格的值数量来做到这一点,但我该如何动态地执行此操作

Wow, thanks for the interesting task. 哇,谢谢你有趣的任务。 I came up with this solution http://jsfiddle.net/PhWGF/4/ . 我想出了这个解决方案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. 您可以将您的表视为常规的2d array ,这一切都归结为经典的嵌套循环。 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. 我们在同一列的每一行中搜索每个单元格的副本,存储第一个和最后一个出现以确定稍后的跨度长度。

Note, you need to set all "roswpan" before deleting duplicates. 注意,您需要在删除重复项之前设置所有“roswpan”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM