【问题标题】:Datatables sort images on title tag数据表对标题标签上的图像进行排序
【发布时间】:2013-07-19 09:31:39
【问题描述】:

我有一个关于为数据表使用自定义排序选项的问题。 我有一个表,最后一列只有图像。图片使用标题标签,我想在其中对它们进行排序。

所以,我使用这段代码来设置排序:

<script type="text/javascript">

            jQuery.extend( jQuery.fn.dataTableExt.oSort, {
                "title-string-pre": function ( a ) {
                    return a.match(/title="(.*?)"/)[1].toLowerCase();
                },

                "title-string-asc": function ( a, b ) {
                    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
                },

                "title-string-desc": function ( a, b ) {
                    return ((a < b) ? 1 : ((a > b) ? -1 : 0));
                }
            } );

            $(document).ready(function() {
                        $('#customertable').dataTable( {
                             "aoColumnDefs": [ 
                             { "bSortable": false, "aTargets": [ 0,1 ] },
                             { "sType": "title-string-asc",   "aTargets": [ 4 ] }
                           ],

                            "bPaginate": false,
                            "bLengthChange": false,
                            "bFilter": false,
                            "bInfo": false,
                            "bAutoWidth": false,
                            "bSortCellsTop": true

                        } );
                    } );
</script>

但是,当我单击第 4 列的标题时,它不起作用并且 Chrome 报告错误“对象 # 的属性 'title-string-asc-desc' 不是函数” 和 "对象#的属性'title-string-asc-asc'不是函数"

我做错了什么?

【问题讨论】:

    标签: datatables


    【解决方案1】:

    找到答案,但不明白。

    改变了 { "sType": "title-string-asc", "aTargets": [4] } 到 { "sType": "title-string", "aTargets": [ 4 ] }

    现在可以了。但为什么? “title-string”在任何地方都没有定义。 javascript 如何将该字符串链接到标题标签的内容?

    【讨论】:

    • Title-string 是它的名字,当你点击标题时它变成 title-string-asc 或 title-string-desc,然后使用你的自定义排序功能...如果你的名字是 title- string-asc,它会变成 title-string-asc-asc 并有 ref 错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    • 2021-07-30
    • 2023-01-24
    • 1970-01-01
    相关资源
    最近更新 更多