javascript - 对 Bootstrap 表中的可见行和相关隐藏行进行排序

标签 javascript jquery html css twitter-bootstrap

我有一张 table ,是用 bootstrap 3 制作的。 我有 2 种行,一种有 4 个 td,我使用它们中的第一个来显示默认情况下隐藏的下一行。 (显示有关前一行的数据)

一切正常。但是,Bootstrap“排序”功能(通过单击标题行)无法按预期工作。它对所有行进行排序,包括隐藏的行,我的系统不再工作了......(当我点击我的主行时,下一行不是隐藏的行...... :( )

有人知道我该如何解决这个问题吗?

HTML:

<table class="table table-striped">
  <thead>
    <th>show data</th>
    <th>name</th>
    <th>adress</th>
    <th>buttons</th>
  </thead>
  <tbody>
    <tr class="mainRow">
      <td class="clickArrow"></td>
      <td>my name</td>
      <td>my adress</td>
      <td>some buttons</td>
    </tr>
    <tr class="subRow">
      <td colspan=4>THE DATA !!!!</td>
    </tr>
  </tbody>
</table>

JS:

$(document).ready(function(){
  $('.subRow').hide();
  $('body').find('.clickArrow').html('<i class="fa fa-arrow-down"></i>');
  $('body').on('click','.clickArrow',function(){
    if($(this).html()=='<i class="fa fa-arrow-down"></i>'){
      $(".clickArrow").html('<i class="fa fa-arrow-down"></i>');
      $('.subRow').hide();
      $('.mainRow td').css('background-color','#DDDACE');
      $(this).parent('tr').find('td').css('background-color','white');
      $(this).html('<i class="fa fa-eye"></i>');
      $(this).parent('tr').next().slideToggle("slow");
    }else{
      $(this).html('<i class="fa fa-arrow-down"></i>');
      $(this).parent('tr').find('td').css('background-color','#DDDACE');
      $(this).parent('tr').next().slideToggle("slow");
    }
  });
});

我不知道 Bootstrap 的“排序”功能到底发生了什么。 也许解决方案是禁用 Bootstrap 排序系统,并实现我的。

我只是想知道是否有人已经遇到过这个问题并找到了一个不错的解决方案。

最佳答案

这个有jquery插件

您可以根据表格标题对表格进行排序

试试 jquery 数据表插件 http://www.datatables.net/manual/styling/bootstrap

关于javascript - 对 Bootstrap 表中的可见行和相关隐藏行进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26016679/

相关文章:

php - 根据 php jQuery 中的下拉选择单击按钮时填充文本框

javascript - 减少 CSS 中两个 block 之间的间隙

jquery - Cordova 无法构建 ios

javascript - 使用 Jquery 动态删除脚本标签时出现问题

javascript - 检查表 tr td 是否不为空

javascript - 如何在 Node.js 中使用 Azure Function App 访问 Azure AD

javascript - 列表更改 onclick

javascript - react JS 错误 "...rest"语法错误 : Unexpected token

javascript - 检查背景中的特定图像

javascript - HTML - 如何在 div 内的 img=src 地址中生成随机数