[英]Grouping HTML table rows with rowspan
I am struggling with this issue for a while and really appreciate if someone can give some idea on how I can move forward with.我在这个问题上苦苦挣扎了一段时间,如果有人能就我如何继续前进提出一些想法,我将不胜感激。
The idea is to reduce the number of rows in the table by grouping the relevant data in the below format.这个想法是通过按以下格式对相关数据进行分组来减少表中的行数。
I need to convert the JSON response coming from server (non-grouped data) to a particular format so that I can paint the table with the grouped data.我需要将来自服务器(非分组数据)的 JSON 响应转换为特定格式,以便我可以使用分组数据绘制表格。
**Initial Layout** +------------+-----------+--------+------------+ | Category | Product | Size | Shipping +------------+-----------+--------+------------+ | Category 1 | Product 1 | Big | Free | | Category 1 | Product 2 | Small | Free | | Category 1 | Product 3 | Big | Free | | Category 1 | Product 4 | Small | Free | +------------+-----------+--------+------------- **Expected Result** +------------+----------------------+--------+----------- | Category | Product | Size | Shipping +------------+----------------------+--------+------------ | Category 1 | Product 1, Product 3 | Big | Free | | | Product 2, Product 4 | Small | Free | +------------+----------------------+--------+----------
More details in the jsfiddle: https://jsfiddle.net/zy8kj2tb/2/ jsfiddle中的更多详细信息: https://jsfiddle.net/zy8kj2tb/2/
// please see the code in jsfiddle
<h3>
Initial layout:
</h3>
<h6>
<p>
Category = Category 1, Category 2, etc or "blank"
</p>
<p>
Product = Product 1, Product 2, etc or "blank"
</p>
<p>
Size = Big, Small, XL, etc or "blank"
</p>
<p>
Shipping = Free, Standard, Expedited, etc or "blank"
</p>
<p>
dont group blank rows with cat, prod, size = make it as individual row
</p>
</h6>
<div id="initialLayout">
</div>
<h3>Expected result:</h3>
<table id="expectedTable" border="1" cellpadding="3" cellspacing="0">
<tr>
<th>Category</th>
<th>Product</th>
<th>Size</th>
<th>Shipping</th>
</tr>
<tr>
<td rowspan=2>Category 1</td>
<td rowspan="2">Product 1, Product 3 <br>Product 2, Product 4</td>
<td rowspan="2">Big <br>Small</td>
<td rowspan="2">Free</td>
</tr>
</table>
<br/>
Just replace your HTML with this one, I did two things -只需用这个替换你的 HTML,我做了两件事 -
- Changed first row with -将第一行更改为 -
<td rowspan="2">Product 1, Product 3 <br>Product 2, Product 4</td>
<td rowspan="2">Big <br>Small
</td>
- Removed respective td tags from the second row从第二行中删除了相应的 td 标签
I just looked at your code我刚看了你的代码
where you have written你写的地方
<td rowspan=2>Category 1</td>
<td>Product 1, Product 3</td>
<td>Big</td>
<td rowspan=2>Free</td>
It should be它应该是
<td rowspan="2">Category 1</td>
<td>Product 1, Product 3</td>
<td>Big</td>
<td rowspan="2">Free</td>
you have just missed some quotes你刚刚错过了一些报价
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.