Tablesorter 2.0.3 colspan问题 [英] Tablesorter 2.0.3 colspan issue

查看:158
本文介绍了Tablesorter 2.0.3 colspan问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Tablesorter 2.0.3时遇到了一些问题。

I a couple of issues using Tablesorter 2.0.3.

第一个问题是我在桌面上设置了一个colspan。基本上当我这样做时,它不会对各自的列进行排序。

The first issue is when I set a colspan on my table. Basically when I do this as below it doesn't sort the respective columns.

<table> 
<thead> 
        <th colspan="3"></th>  
        <th>Four</th> 
        <th>Five</th>
        <th>Six</th>
        <th>Seven</th>  
</thead> 
<tbody> 
<tr> 
        <td>1</td> 
        <td>2</td> 
        <td>3</td> 
        <td>4</td>
        <td>5</td> 
        <td>6</td>
        <td>7</td>
</tr>  
</tbody> 
</table> 

我遇到的第二个问题是无论我设置sortInitialOrder(desc或asc) )在tablesorter.js中,单击它时对排序进行升序或降序没有任何影响。

The second issue I have is that no matter what I set the sortInitialOrder ("desc" or "asc") in the tablesorter.js, it doesn't have any effect to making the sort ascending or descending when it is clicked on.

请问任何人都可以帮忙吗?

Please can anyone help?

推荐答案

要解决问题1,您可以创建自己的标题到数据列的映射。这就是我按照我想要的方式做的功能。

To solve problem one you can create your own mapping of headers to data cols. here's what I did to get the functionality the way I wanted.

我已经将以下方法添加到tablesorter.js:

I've added the following method to tablesorter.js:

function findInMap(map, index, reverse) {
    for(var i = 0; i < map.length; ++i) {
        if(map[i][reverse ? 1 : 0] == index) return map[i][reverse ? 0 : 1];
    }

    return index;
}

还将以下内容添加到 this.defaults

customMap: []

更改以下方法:

function setHeadersCss(table,$headers, list, css) {
    $headers.removeClass(css[0]).removeClass(css[1]);

    var h = [];
    $headers.each(function(offset) {
        if(!this.sortDisabled) {
            h[this.column] = $(this);                   
        }
    });

    var l = list.length; 

    for(var i=0; i < l; i++) {
        var header = list[i];
        var headerIndex = findInMap(table.config.customMap, header[0], true);
        h[headerIndex].addClass(css[header[1]]);
    }
}

最后但并非最不重要的是,添加/更改以下内容 $ headers.click(function(e){

Last but not least, add/change the following in $headers.click(function(e) {

添加:

var ia = findInMap(config.customMap, i, false);

更改:
config.sortList.push([i,this.order]); config。 sortList.push([ia,this.order]);

当你初始化tablesorter传递一个 customMap [ [header_col_id,data_col_id]] 在您的情况下,它将是:

When you init the tablesorter pass a customMap[[header_col_id, data_col_id]] In your case it'll be:

customMap[
    [2, 4],
    [3, 5],
    ...
]

这篇关于Tablesorter 2.0.3 colspan问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆