2023-09-24 15:16:23

221

Táblázat szűrése

Szemléltetés:

Név Hoszt Épület
Ádám D-003-654 SZI
Péter N-001-123 EZP
Imi D-003-123 LF
Feri N-003-987 LF
Közös W-001-001 SZI

js:

  1. function tablaSzureseMind(){
  2. table = document.getElementById("tabla");
  3. trs = table.getElementsByTagName("tr");
  4. inputs = table.getElementsByTagName("input");
  5. for (i = 0; i < trs.length; i++) {
  6. isSorRejt=false;//sort meg kell jeleníteni
  7. for(j = 0; j < inputs.length; j++){
  8. td = trs[i].getElementsByTagName("td")[j]; //vizsgált cella
  9. if (td) {
  10. txtValue = td.textContent || td.innerText;
  11. if ( !(txtValue.toUpperCase().indexOf(inputs[j].value.toUpperCase()) > -1) ) {
  12. isSorRejt=true;
  13. }
  14. }
  15. }
  16. if(isSorRejt){
  17. trs[i].style.display ="none";
  18. }else {
  19. trs[i].style.display ="";
  20. }
  21. }
  22. }

html:

  1. <table id="tabla">
  2. <tr class="Szuro">
  3. <th><input type="text" id="nev" onkeyup="tablaSzureseMind()" placeholder="Név"></th>
  4. <th><input type="text" id="hoszt" onkeyup="tablaSzureseMind()" placeholder="Hoszt"></th>
  5. <th><input type="text" id="epulet" onkeyup="tablaSzureseMind()" placeholder="Hely"></th>
  6. </tr>
  7. <tr class="header">
  8. <th>Név</th>
  9. <th>Hoszt</th>
  10. <th>Épület</th>
  11. </tr>
  12. <tr>
  13. <td>Ádám</td>
  14. <td bgcolor="green">D-003-654</td>
  15. <td>SZI</td>
  16. </tr>