Hey there, I'm currently working with two HTML tables labeled id="source" and id="destination".
The source table contains 7 columns while the destination table only has 5 columns.
My goal is to filter data based on col2 (with a value of 150) from the source table into the destination table. However, I only want to display columns 1, 3, 4, 5, and 6, completely ignoring col2 and col7 as shown in the image below. https://i.sstatic.net/3Ruod.png I've come across examples using jQuery for this task, but I prefer to achieve it using pure JavaScript since I'm not very familiar with jQuery. I have attempted to create two functions for this purpose, but unfortunately, I am still not obtaining the desired results.
function copytable() {
var source = document.getElementById('source');
var destination = document.getElementById('destination');
var copy = source.cloneNode(true);
copy.setAttribute('id', 'destination');
destination.parentNode.replaceChild(copy, destination);
filterTable();
}
function filterTable() {
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("destination");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}