首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在jQuery.tablesorter中禁用列排序?

如何在jQuery.tablesorter中禁用列排序?
EN

Stack Overflow用户
提问于 2012-01-20 22:35:03
回答 5查看 24.6K关注 0票数 20

我试图找到一种方法来禁用对列的排序。我使用jQuery插件tablesorter。默认情况下,如果你点击标题单元格,它会对列数据进行排序,但如果我不需要对四列表格中的一列或两列进行排序,我需要做的是什么。

提前谢谢。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2012-01-20 22:40:16

您必须在初始化时传递相应的参数,例如:

代码语言:javascript
复制
{ ...
   headers: { 0: { sorter: false} }
}

有关详细信息,请查看手册,网址为:

http://tablesorter.com/docs/

票数 28
EN

Stack Overflow用户

发布于 2014-01-12 23:56:15

您还可以使用html数据属性:

代码语言:javascript
复制
<th data-sorter="false">...</th>

或者,您可以使用一个类:

代码语言:javascript
复制
<th class="sorter-false">...</th>
票数 21
EN

Stack Overflow用户

发布于 2012-01-20 22:39:37

类似于:

代码语言:javascript
复制
$('#selector').tablesorter({headers: {0: { sorter: false}}});

这里清楚地描述了这一点:http://tablesorter.com/docs/example-options-headers.html

代码语言:javascript
复制
$(document).ready(function() { 
    $("#myTable").tablesorter({ 
        // pass the headers argument and assing a object 
        headers: { 
            // assign the secound column (we start counting zero) 
            1: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            }, 
            // assign the third column (we start counting zero) 
            2: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            } 
        } 
    }); 
});
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.21.2/js/jquery.tablesorter.min.js"></script>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.21.2/css/theme.blue.min.css' type='text/css' />
<table id='myTable' cellspacing="1" class="tablesorter-blue">             
    <thead>> 
        <tr> 
            <th>first name</th> 
            <th>last name</th> 
            <th>age</th> 
            <th>total</th> 
            <th>discount</th> 
            <th>date</th> 
        </tr> 
    </thead> 
    <tbody> 
        <tr> 
            <td>peter</td> 
            <td>parker</td> 
            <td>28</td> 
            <td>$9.99</td> 
            <td>20%</td> 
            <td>jul 6, 2006 8:14 am</td> 
        </tr> 
        <tr> 
            <td>john</td> 
            <td>hood</td> 
            <td>33</td> 
            <td>$19.99</td> 
            <td>25%</td> 
            <td>dec 10, 2002 5:14 am</td> 
        </tr> 
        <tr> 
            <td>clark</td> 
            <td>kent</td> 
            <td>18</td> 
            <td>$15.89</td> 
            <td>44%</td> 
            <td>jan 12, 2003 11:14 am</td> 
        </tr> 
        <tr> 
            <td>bruce</td> 
            <td>almighty</td> 
            <td>45</td> 
            <td>$153.19</td> 
            <td>44%</td> 
            <td>jan 18, 2001 9:12 am</td> 
        </tr> 
        <tr> 
            <td>bruce</td> 
            <td>evans</td> 
            <td>22</td> 
            <td>$13.19</td> 
            <td>11%</td> 
            <td>jan 18, 2007 9:12 am</td> 
        </tr> 
    </tbody> 
</table>

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8942974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档