I have a set of elements. Some of these are part of section "Film", others of section "Video" and still others of section "VideoYoutube". There is a special column that defines this Section.
The elements in the table that are part of section "Film" must be placed at the bottom of the table.
To be able to put the elements at the bottom of the table I know that you have to use the command:
insertRow(-1);
Since my table is dynamic, how can I set what I want?
Items.forEach(function (item) {
let child = document.createElement("tr");
child.innerHTML = `
<td>${item.id}</td>
<td>${item.title}</td>
<td>${item.image}</td>
<td>${item.section}</td>
<td>${item.date}</td>`;
table.appendChild(child);
})
<table id="my-table" width="90%">
<tr>
<th>Id</th>
<th>Title</th>
<th>Image</th>
<th>Section</th>
<th>Date</th>
</tr>
</table>
To understand better, I have to filter by Film only
Example to understand
let itemarr = [{
id: 1,
title: "image 1",
image: "url 1",
section: "Film",
date: "date 1",
}, {
id: 2,
title: "image 2",
image: "url 2",
section: "Video",
date: "date 2",
},
{
id: 3,
title: "image 3",
image: "url 2",
section: "Film",
date: "date 2",
},
{
id: 4,
title: "image 4",
image: "url 2",
section: "Video",
date: "date 2",
}]
itemarr.forEach(function(item) {
let child = document.querySelector('table').insertRow(-1)
child.innerHTML = `
<td>${item.id}</td>
<td>${item.title}</td>
<td>${item.image}</td>
<td>${item.section}</td>
<td>${item.date}</td>`
})
<table id="my-table" width="90%">
<tr>
<th>Id</th>
<th>Title</th>
<th>Image</th>
<th>Section</th>
<th>Date</th>
</tr>
</table>