jQuery中的Tablesorter和multi textExtraction? [英] Tablesorter and multi textExtraction in jQuery?

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

问题描述

我有这张带有TableSorter插件的表.

I have this table which has TableSorter plugin.

Jsbin#1

但是-我希望列#1(从第二个零开始)由 第一个字符 第二个字符作为数字排序!)

However - I want for column #1 ( second zero based) to be sorted by the first char second char as digit !)

示例:

4134 (I dont care about the other digits order - just the first one which is here=1)
22230 //2
242   //4
67    //7
28    //8
992222 //9

因此,我创建了另一个 textExtraction函数:(仅在第一列中应用)

So I created another textExtraction function : ( which is going to be applied only at the first column)

    var myExtraction = function(node) {
  return parseInt($(node).substring(1))
}

向ctor中添加了另一个对象,该对象仅适用于列#1.(基于0').

and added another object to the ctor which is only for column #1.(0'based).

...,{
    textExtraction: myExtraction,
    headers: {
        1: {
            sorter: 'digit'
        } 
    }
}

但是它没有( jsbin#2在这里 新jsbin )可以正常工作,而且我很确定这是不可能的.

However it doesn't ( jsbin#2 is here new jsbin) work and i'm pretty sure this is not the way.

有什么需要帮助的吗?

Any help please?

推荐答案

我不确定您是否完全需要自定义myExtraction.只需将该列的排序器更改为'text'而不是'digit',当您与其余标题一起指定该排序器时,它应该可以工作.

I'm not sure you need the custom myExtraction at all. Just change the sorter for that column to 'text' instead of 'digit' and it should work when you specify it with the rest of the headers.

修改

如果要使用 second 位进行排序:

If you want the second digit to be used for sorting:

var myExtraction = function(node) {
  return $(node).text().substring(1);
}

jQuery('#bullsTable').tablesorter(
{
    headers: {
        0: {
            sorter: false
        },
        1: {
            sorter: 'text'
        },
        13: {
            sorter: 'digit'
        }, 
        14: {
            sorter: 'digit'
        }
    },
      textExtraction: jgExtraction,
      textExtraction: {
         1: myExtraction
      }
}

我在这里更新了 jsbin .

注意:您使用的旧版本的表排序器似乎不支持textExtraction.我更新了<script>标记,它可以正常工作.

Note: you were using an old version of tablesorter that didn't appear to support textExtraction. I updated the <script> tag and it works.

这篇关于jQuery中的Tablesorter和multi textExtraction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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