filtering - filter rows with dropdown using jQuery -


i'm having heck of time getting work. should simple, every route i've tried has not worked. here's jquery i'm using now:

<script type="text/javascript">     $(document).ready(function () {          //filter list year         $(function () {             $("#ddyear").change(function (evt) {                 var year = $("#ddyear").val();                  $('tr').show();                  $("td[id^='accessrequestid']").each(function () {                     alert("checking " + this.val);                     if ($(this).attr("class") == ".ar_" + year) {                         alert("hiding " + this.val);                         $(this).parent().hide();                     }                 });             });         });     }); </script> 

and here's table i'm trying filter:

<div class="index-header">select year view: <%:html.dropdownlist("ddyear", model.yearlist, null %></div>  <table id="artable">     <tr>         <th>             year         </th>         <th>             version         </th>         <th>             name         </th>      </tr>      <% foreach (var item in model.accessrequests) { %>          <tr class="clickable">             <td id="accessrequestid<%=item.access_request_id%>" class="<%:string.format("ar_{0}", item.record_year) %>">                 <%: html.displayfor(modelitem => item.record_year) %>             </td>             <td>                 <%: html.displayfor(modelitem => item.version_no) %>             </td>             <td>                 <%: html.displayfor(modelitem => item.employee_name) %>             </td>         </tr>      <% } %>  </table>   

i tried doing this:

$("td[id^='accessrequestid']").parent().hide().filter('.ar_' + year).show(); 

and while filtered rows out great, didn't unfilter them in when should have. tried adding $("td[id^='accessrequestid']").parent().show; reset first, didn't thing. (i tried .each(), can see in last try). advice or appreciated!

try fiddle http://jsfiddle.net/96evt/ code below , added demo table rows in fiddle too.

$("#ddyear").on('change', function () {         var year = $("#ddyear").val();         $('tr').show();          $("td.ar").each(function (index, tdar) {             if ($(tdar).hasclass("ar_" + year)) {                 $(tdar).parent('tr').hide();             }         }); }); 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -