Reputation: 652
Looking for a css or jquery solution to break these dynamically loaded tables into a max of 6 per row , the script that creates the tables places them all inline , and sometimes up to 32 td.tables are shown in one row. How can i break them where only a max of 6 are to show inline
here is the HTML
<table class="scoreboardboxscore">
<tbody>
<tr data-bind="foreach: matchups">
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
<td>
<table class="boxscoretable"></table>
</td>
</tr>
</tbody>
</table>
Upvotes: 1
Views: 281
Reputation: 5178
You can take all td
s from table, put them into newly created tr
s and remove original tr
at the end:
$(document).ready(function()
{
var elementsPerRow = 6;
var currentTr = $('<tr>');
var table = $('.scoreboardboxscore');
var tds = $('.scoreboardboxscore tr:first td');
tds.each(function(index)
{
currentTr.append(this);
if (index % elementsPerRow == elementsPerRow - 1)
{
table.append(currentTr);
currentTr = $('<tr>');
}
else if (index + 1 == tds.length)
{
table.append(currentTr);
}
});
$('.scoreboardboxscore tr:first').remove();
});
Upvotes: 1