更改表的排序方式jQuery tablesorter [英] Changing the way table is sorted jquery tablesorter

查看:171
本文介绍了更改表的排序方式jQuery tablesorter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery tablesorter对我的表进行排序.我试图用谷歌搜索我的问题,没有找到我想要的东西.

I'm using jquery tablesorter to sort my table. I've tried to google my question, didn't find what I was looking for.

我有一个表,该表的内容会动态更改,因此我想更改项目的排序方式.

I've got a table which content changes dynamically so I want to change the way items are sorted.

在一种情况下,我在表中填充了可以使用默认.tablesorter()进行排序的文本,而在另一种情况下,表中存在数字,因此我需要像这样调用tablesorter:

One case I've got table populated with text which can be sorter with default .tablesorter() and I've got another case where digits are in table so I need to invoke tablesorter like this :

$('table').tablesorter({
        headers : { 
                0 : {sorter:'digit'},
                1 : {sorter:'digit'},
                2 : {sorter:'digit'},
                3 : {sorter:'digit'}
        }
    });

我有一个方法可以重新加载表格内容中数字/文本之间的表格切换,如何更改表格的排序方式.

I have a method that does reload to table switching between numbers/text in table content, how can I change the way table is sorted.

在示例中(伪代码):

function reloadTableData
if table contains numbers user this tablesorter (I have a way to know if table contains numbers) 
$('table').tablesorter({
            headers : { 
                    0 : {sorter:'digit'},
                    1 : {sorter:'digit'},
                    2 : {sorter:'digit'},
                    3 : {sorter:'digit'}
            }
        });
if table contains text use ordinary table sorter 
$('table').tablesorter();
end

我可以用文本/数字重载表格数据n次.

I can reload table data n times with either text/numbers.

我尝试了以下方法:

function initTablesorter(n) {

    switch(n)
    {
    case "number":
      digitTableSorter();
      break;
    case "text":
     defaultTableSorter();
      break;
    default:

    }
}

function digitTableSorter(){
$('table').tablesorter({
        headers : { 
                0 : {sorter:'digit'},
                1 : {sorter:'digit'},
                2 : {sorter:'digit'},
                3 : {sorter:'digit'}
        }
    });
}

function defaultTableSorter(){
$('table').tablesorter();
}

不用说这是行不通的,我希望有人以前做过类似的事情,现在我被困了一段时间.

Needless to say it's not working, I hope someone did something like this before, I'm stuck for some time now.

推荐答案

所以它不起作用,因为您正在重新初始化表上的tablesorter?您可以在重新绑定表排序器之前尝试解除其绑定.

So is it not working because you are reinitialising tablesorter on a table? You may try to unbind tablesorter before rebinding it.

$('table')
 .unbind('appendCache applyWidgetId applyWidgets sorton update updateCell')
 .removeClass('tablesorter')
 .find('thead th')
 .unbind('click mousedown')
 .removeClass('header headerSortDown headerSortUp');

看看从表中删除jQuery tablesorter .

这篇关于更改表的排序方式jQuery tablesorter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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