简体   繁体   English

tablesorter不显示向上和向下箭头

[英]tablesorter doesn't show up and down arrows

I am trying to use the JQuery tablesoter plugin but when it comes to show the arrows it doesn't show either down or up arrow when I sort descending or ascending order. 我正在尝试使用JQuery tablesoter插件但是当它显示箭头时,当我按降序或升序排序时,它不会显示向下或向上箭头。 It always shows up and down arrow (unsorted arrow). 它始终显示向上和向下箭头(未分类的箭头)。 It seems table.tablesorter .header {...} overrides the table.tablesorter .headerSortUp {...} and table.tablesorter .headerSortDown{...} styles. 似乎table.tablesorter .header {...}会覆盖table.tablesorter .headerSortUp {...}和table.tablesorter .headerSortDown {...}样式。 Below is my code : 以下是我的代码:

CSS CSS

table.tablesorter .headerSortUp {
    background-image: url('../images/icons/asc.gif');
    background-repeat: no-repeat;
    background-position: center right;
}
table.tablesorter .headerSortDown {
    background-image: url('../images/icons/desc.gif');
    background-repeat: no-repeat;
    background-position: center right;
}
table.tablesorter .header {
    cursor: pointer;
    background-image: url('../images/icons/bg.gif');
    background-repeat: no-repeat;
    background-position: center right;
}

My table is in a velocity template but I don't think that will affect for this problem. 我的表位于速度模板中,但我认为这不会影响此问题。

<table id="harvestTable" class="tablesorter" border="1">
      <thead>
      <tr>
        <th>Source</th>
        <th>Time</th>
      </tr>
      </thead>
      <tbody>
      #foreach($item in $self.harvestlist)
        #set($harvestId = $item.getFirst('harvestId'))
...

And I have included the relevant icons at respective folders. 我已在相应的文件夹中包含相关图标。 I am using the chrome and tested this on firefox as well but doesn't work in both. 我正在使用chrome并在firefox上对此进行了测试,但两者都不兼容。 When I inspect the element in chrome, I can see that .header's image has overriden the .headerSortUp and .headerSortDown images. 当我检查chrome中的元素时,我可以看到.header的图像覆盖了.headerSortUp和.headerSortDown图像。 If i unselect .header's image, .headerSortUp image is correctly shown. 如果我取消选择.header的图像,则会正确显示.headerSortUp图像。

Have I missed something here? 我错过了什么吗? I really appreciate the valuable responses. 我非常感谢有价值的回应。

Thanks 谢谢

The problem you are having is due to css specificity (try out this calculator ): 您遇到的问题是由于css特异性 (尝试这个计算器 ):

The default blue theme uses: 默认的蓝色主题使用:

table.tablesorter thead tr .headerSortUp {} // (0,0,2,3)

so, in order to override this, you'll need a higher css specificity. 所以,为了覆盖它,你需要更高的css特异性。 One way would be to add a th to the sort class: 一种方法是添加一个th来排序类:

table.tablesorter thead tr th.headerSortUp {} // (0,0,2,4)

This is due to css preference rule. 这是由于css偏好规则。 Last matched rule is always applied. 始终应用上次匹配的规则。 to overcome this situation you can always use !important modifier, like in your case 要克服这种情况,你可以随时使用!important修饰符,就像你的情况一样

table.tablesorter .headerSortDown {
 background-image: url('../images/icons/desc.gif') !important;

or 要么

you just put .header css before .headerSortDown and .headerSortUp and it will start working. 你只需将.header css放在.headerSortDown和.headerSortUp之前,它就会开始工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM