One way to achieve this in a Razor Page is to use JavaScript/jQuery to detect when the dropdownlist value changes and then iterate through all the rows in the table. For each row, check if all the cells are empty and if so, remove the row. Here's an example:
<select id="myDropdown" onchange="filterRows()"> <option value=""></option> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option> </select>
function filterRows() { var selectedValue = document.getElementById("myDropdown").value; var tableRows = document.getElementById("myTable").getElementsByTagName("tr"); for (var i = 1; i < tableRows.length; i++) { // start at 1 to skip the header row var cells = tableRows[i].getElementsByTagName("td"); var isEmpty = true; for (var j = 0; j < cells.length; j++) { if (cells[j].innerHTML.trim() !== "") { isEmpty = false; break; } } if (isEmpty && (selectedValue === "" || selectedValue === null)) { tableRows[i].parentNode.removeChild(tableRows[i]); } } }
In the innermost loop, check if any of the cells in the current row are not empty. If at least one cell is not empty, set the isEmpty flag to false.
After checking all the cells, check if the row is empty and the dropdownlist value is either null or empty. If both conditions are true, delete the row using the parentNode.removeChild method.
Note that this example assumes the table has a header row and that all the content cells are td tags. You may need to adjust the code to fit your specific table layout.
Asked: 2022-02-12 11:00:00 +0000
Seen: 10 times
Last updated: Sep 27 '22