Estoy filtrando una tabla y exportándola a Excel. Para excluir las filas filtradas, tengo que configurar data-exclude="true" en el elemento 'tr'
function Search() { var input, filter, table, tr, td, i, txtValue; input = document.getElementById("myInput"); filter = input.value.toUpperCase(); table = document.getElementById("myTable"); tr = table.getElementsByTagName("tr"); for (i = 0; i < tr.length; i++) { td = tr[i].getElementsByTagName("td")[7]; if (td) { txtValue = td.textContent || td.innerText; if (txtValue.toUpperCase().indexOf(filter) > -1) { tr[i].style.display = "" ; //Set here the Code data-exclude="false" } else { tr[i].style.display = "none"; //Set here the Code data-exclude="true"; } } } }``
Puede actualizar los atributos de un elemento usando la función setAttribute
tr.setAttribute('data-exclude', true)
Puede usar la función getAttribute para obtener el valor de un atributo específico. Tenga en cuenta que el valor se devuelve como una cadena y debe convertirse a un valor booleano en su caso para filtrar