javascript - Getting the size of visible table rows -


i have drop down option , every time drop down option changes, content of table being filtered based on value of drop down. however, want display message if in table filtered (basically if shows nothing). have code, not consider visibility of table row.

alert(document.getelementbyid("table").rows.length); 

drop down (html):

<td>     room preference: <a style="color: red;">*</a> </td> <td>     <select name="roompreference" id="roompreference" class="form-control placeholder-no-fix" onchange="setrooms();">         <option value="ward">ward</option>         <option value="semi-private">semi-private</option>         <option value="private">private</option>         <option value="suite room">suite room</option>         <option value="icu">icu</option>         <option value="iso">iso</option>     </select> <br> </td> 

table (html):

<table class="table table-bordered table-striped table-condensed" id="table">     <thead>         <tr>             <th width="1px">                 admit             </th>             <th>                 room number             </th>             <th>                 room type             </th>         </tr>     </thead>     <tbody>         <%             arraylist<room> rooms = (arraylist)session.getattribute("rooms");             for(room r: rooms) {                 if(r.getstatus().equals("available")) {         %>         <tr>             <td align="center">                 <input type="radio" name="room" value="<%=r.getroomnumber()%>">             </td>             <td>                 <%=r.getroomnumber()%>             </td>             <td>                 <%=r.getroomtype()%>             </td>         </tr>         <%}}%>     </tbody>     <thead>         <tr>             <td colspan="3" align="center" style="color: red;">                 there no available rooms.             </td>         </tr>     </thead> </table> 

javascript:

setrooms(); function setrooms() {     var $rows = $('#table tbody tr');     var val = document.getelementbyid("roompreference").value,         reg = regexp(val),         text;     $rows.show().filter(function() {         text = $(this).text().replace(/\s+/g, ' ');         return !reg.test(text);     }).hide();     var size = 0; } 

a possible jquery solution:

$("#table tbody tr:visible").length

will give count of visible table rows.

example here.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -