2015-02-11 33 views
0

我创建了一个过滤器,仅显示包含td的行,并且从下拉列表中选择值。过滤器工作正常第一次,但第二次我运行它,所有行消失,我不知道为什么。 这是我的过滤器:表上的jquery过滤器第一次工作,但之后隐藏所有行

$(document).ready(function(){ 
    $('select[name=selectedName]').change(function() { 
     $('tr').filter(function() { 
      return $(this).find('td.userName').filter(function() { 
       return $(this).text().indexOf($('select[name=selectedName]').val()) == -1; 
      }).length; 
     }).hide(); 
    }); 
}); 

下拉:

$query = "SELECT user_name FROM users"; 
$result = mysql_query($query); ?> 
<select name="selectedName" id="userSelected"> 
    <option value="" disabled selected>user name</option> 
    <?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> 
     <option value="<?php echo $line['user_name'];?>"> 
      <?php echo $line['user_name'];?> 
     </option> 
    <?php } ?> 
</select> 

和表的最后创作:

<table class="table table-bordered table-hover" ng-controller="tableCtrl"> 
     <thead> 
     <th>user name</th> 
     <th>script name</th> 
     <th>cron format<span class="glyphicon glyphicon-question-sign"></span></th> 
     <th>schedule last update</th> 
     <th>next execution time</th> 
     <th>script exec</th> 
     </thead> 
     <tbody ng-repeat="(user_id,script_id) in data"> 
      <tr ng-repeat="(script_id, cron_format) in script_id"> 
       <td class="userName">{{user(user_id)}}</td> 
       <td class="scriptName">{{script(script_id)}}</td> 
       <td class="cronFormat"><span contenteditable="true" ng-repeat="l in letters(cron_format) track by $index">{{l}}</span></td> 
       <td>{{compare(user_id,script_id,cron_format)[0]}}</td> <!--[0] represents scheduler last update--> 
       <td>{{compare(user_id,script_id,cron_format)[1]}}</td> <!--[1] represents next execution time--> 
       <td>{{compare(user_id,script_id,cron_format)[2]}}</td> <!--[2] represents script_exec--> 
      </tr> 
     </tbody> 
    </table> 

任何想法为什么会发生?感谢您的帮助......

UPDATE

我加入$('tr').show();和功能,除了工作,我怎么能在下拉菜单中增加价值来显示所有的表/取消过滤器?

回答

2

你照顾隐藏的行,但你永远不会显示他们回来。这就是为什么你的表迟早会隐藏所有的行。

+0

好点:)...我编辑了我的问题...解决方案仍然无法正常工作... – user3194267 2015-02-11 22:38:31

+0

在调用'.filter()'调用之前调用'.show()'方法。 – 2015-02-11 22:43:21

相关问题