首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带连字符的Jquery表Jquery数

带连字符的Jquery表Jquery数
EN

Stack Overflow用户
提问于 2016-05-06 18:41:24
回答 2查看 174关注 0票数 1

Jquery tablesorter

我正在使用,我需要一个sort列,其中包含带有连字符标记的数字。这些数据的格式如下,未能按ASC顺序onLoad:17-143,17-162,12-144,17-45,18-12,17-65,18-2。有些值为空。sql中的空白值。以上数据默认为: 12-144,17-45,17-65,17-143,17-162,18-2,18-12。

请协助。下面是我试图使用的片段:

代码语言:javascript
复制
<script src="https://github.com/christianbach/tablesorter/blob/master/jquery.tablesorter.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $("#main_gvResource").tablesorter.addParser({ 
        // set a unique id 
        id: 'lblIDSort',
        is: function(s) {
            return false;
        },
        format: function(s) {
            return s.replace('$','').replace(/-/g,'');
        }, 
        type: 'numeric' 
    }); 
    $(function() {
        $("#main_gvResource").tablesorter({
           widgets: ['zebra'],
            headers: {
                1: {//zero-based column index
                    sorter:'gdMobileID'
                }
            }
        });
    });
});
</script>

EN

回答 2

Stack Overflow用户

发布于 2016-05-06 19:34:07

为什么有这么多空白?你害怕吗,你可能一下子就看到太多的代码了吗?)

代码语言:javascript
复制
$(function() {
    $.tablesorter.addParser({ 
        _regex: /^\d+(?:-\d+)+$/,
        _formatNumber: function(nr){
            //return "0".repeat(5-nr.length) + nr;
            while(nr.length < 5) nr = "0" + nr;
            return nr;
        },

        // set a unique id 
        id: 'gdMobileID',
        is: function(s) {
            //to auto-recognize the column-type
            return this._regex.test(s); 

            //to apply only on columns you defined
            return false;
        }, 

        format: function(s){
            return s.replace(/\d+/g, this._formatNumber);
        }, 
        type: 'text',
    }); 

    $("#main-gvResource").tablesorter({
        widgets: ['zebra'],
        //no need, if you let the parser auto-recognize the columns to apply
        /*headers: {
            1: {//zero-based column index
                sorter:'gdMobileID'
            }
        }*/
    });
});
票数 0
EN

Stack Overflow用户

发布于 2016-05-07 17:00:34

默认情况下,我的餐盘叉使用自然排序算法。您不需要包含任何额外的代码来使它与数据集(演示)一起工作。

代码语言:javascript
复制
$(function () {
    $('table').tablesorter({
        theme: 'blue'
    });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37079329

复制
相关文章

相似问题

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