Answer the question
In order to leave comments, you need to log in
How to merge cells in html table if they are similar?
Good evening everyone. There is a table:
Mon Tue Wed Thu Fri
Day off Day off 10:00-21:00 10:00-21:00
And you need to get:
Mon-Wed Thu-Fri
Day off 10:00-21:00
You can use js, jquery,
Tell me please in which direction to dig?
Answer the question
In order to leave comments, you need to log in
I'm probably exaggerating, but...
<table border>
<thead>
<td>ПН</td>
<td>ВТ</td>
<td>СР</td>
<td>ЧТ</td>
<td>ПТ</td>
<td>СБ</td>
<td>ВС</td>
</thead>
<tr id="state">
<td>Выходной</td>
<td>Выходной</td>
<td>Выходной</td>
<td>Выходной</td>
<td>15-21</td>
<td>15-21</td>
<td>16-21</td>
</tr>
</table>
var
$Table = $("<table />"),
$Thead = $("<thead />").appendTo($Table),
$Row = $("<tr />").appendTo($Table),
$_tds = $("#state td"), $_heads = $("thead td"),
start, i = 0;
for(; i < $_tds.length; i++){
start = i;
while(
$_tds.get(i++) && $_tds.eq(i).text() == $_tds.eq(i - 1).text()
){}
$Row.append(
"<td>" + $_tds.eq(--i).text() + "</td>"
);
$Thead.append(
"<td>" + (i == start ? "" : $_heads.eq(start).text() + "-") + $_heads.eq(i).text() + "</td>"
);
}
$("table").replaceWith($Table);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question