Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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:

  1. Add an onchange attribute to your dropdownlist that calls a JavaScript function:

<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>

  1. In the JavaScript function, get the dropdownlist value and iterate through all the table rows:

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]); } } }

  1. 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.

  2. 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.