【问题标题】:Sort numbers in jQuery Datatables对 jQuery 数据表中的数字进行排序
【发布时间】:2016-06-20 15:36:27
【问题描述】:

我有一个有 6 列的表,我用的是数据表:

 $('#datatable2').dataTable({
                "oLanguage": { "sSearch": "Search " },
                "oSearch": { "sSearch": "<% = requestId %>" }
               });

当我使用这张表时,它看起来很漂亮,但它没有对数字进行排序 当我添加这个

 $('#datatable2').dataTable({
                     "aoColumns": [
                               { "sType": "numeric-comma" },
                               null,
                               null,
                               null, null, null],

                "oLanguage": { "sSearch": "search: " },
                "oSearch": { "sSearch": "<% = requestId %>" }
               });

它对数字进行了正确排序,但它显示的所有行都不是 10 x 10 或 50 x 50 的图片

请帮忙!

当我使用这段代码时

paging:true,
"aoColumns": [{ "sType": "numeric" }, null, null,null , null, null],

它显示为 gridview

它按我的需要排序,但为什么它在第二行得到数字 129?

请注意:- 我的整数是超链接

【问题讨论】:

    标签: javascript jquery asp.net sorting datatables


    【解决方案1】:

    您必须启用分页,所以datatables 知道如何处理超过页面长度的行数。参数paging = true (https://datatables.net/reference/option/paging)。

    $('#datatable2').dataTable({
        "aoColumns": [
            { "sType": "numeric-comma" },
            null,
            null,
            null,
            null,
            null],
        "paging": true,
        "oLanguage": { "sSearch": "search: " },
        "oSearch": { "sSearch": "<% = requestId %>" }
    });
    

    您还可以更改分页类型https://datatables.net/reference/option/pagingType

    请注意,pagingpagingType 参数是在 datatables 1.10 中引入(或更确切地说是重命名)。

    对于这些参数的旧版名称,请检查https://legacy.datatables.net/usage/options

    更新:要为表格设置默认排序,您必须指定order 参数https://datatables.net/reference/option/order

    您的表初始化将如下所示:

    $('#datatable2').dataTable({
        "aoColumns": [
            { "sType": "numeric-comma" },
            null,
            null,
            null,
            null,
            null],
        "paging": true,
        "oLanguage": { "sSearch": "search: " },
        "oSearch": { "sSearch": "<% = requestId %>" },
        "order": [[ 0, 'asc' ]]
    });
    

    我仍然不确定我是否完全理解您的问题,抱歉。

    【讨论】:

    • 感谢您的宝贵时间,但是当我使用"sType": "numeric-comma" 时,它会正确排序但没有分页作为问题中的第一张图片,并且当我使用"sType": "numeric" 它可以很好地查看分页,但在问题中显示第二行排序错误作为第二张图片。
    • 可能与 RTL 支持有关吗?尝试从左到右设置。
    • 抱歉看不懂,但我忘了说第一列是带超链接的数字
    猜你喜欢
    • 2018-02-24
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多