【问题标题】:Datatables: Custom types数据表:自定义类型
【发布时间】:2011-08-11 13:22:23
【问题描述】:

我在使用 jquery.datatables.js 为我的数据表创建自定义类型时遇到了一些问题。

我的表初始化如下所示:

    drawTable['#<?= $tab ?>'] = function() {
                    $('#sites_<?= $tab ?>').dataTable({
                    'iDisplayLength' : 25,
                    'aaSorting': [[5, 'desc']],
                    'aLengthMenu': [[25, 50, 100, -1], [25, 50, 100, 'All']],
                    'aoColumns' : [
                        {'sType' : 'formatted-num'},
                        null,
                        null,
                        null,
                        {'sType' : 'formatted-num'},
                        {'sType' : 'formatted-num'},
                        {'sType' : 'formatted-num'},
                        {'sType' : 'formatted-num'},
                        {'sType' : 'formatted-num'},
                        {'sType' : 'formatted-num'}
                    ]
                })
};

然后:

$(document).ready(function() {
                drawTable['#<?= $tab ?>']();
                drawnTable['#<?= $tab ?>'] = true;
            });

$tab 是从服务器中选择一些值。

这适用于自定义类型,但我需要创建自己的类型。我该怎么做?我一直在阅读这里的一些示例:http://www.datatables.net/plug-ins/type-detection,但所有这些似乎都是针对仅以 $(document).ready(function() { $('#example').dataTable(); } ); 开头的表完成的

不确定如何在我的专栏中至少实现其中之一,如果我至少可以做到这一点,我会编写自己的函数。谢谢!

【问题讨论】:

    标签: jquery html datatables


    【解决方案1】:

    这样做是这样的:

        jQuery.fn.dataTableExt.oSort['num-html-asc']  = function(a,b) {
        a = ;//changes to remove html signs
        b = ;//same as above
        return ((a < b) ? -1 : ((a > b) ?  1 : 0));
    };
    
    jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
        a = ;//changes to remove html signs
        b = ;//same as above
        return ((a < b) ? 1 : ((a > b) ?  -1 : 0));
    };
    

    在包含 datatables.js 之后,但在初始化之前包含该函数。然后在需要使用那个的列中

    {'sType' : 'num-html'},
    

    就是这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 2011-06-17
      • 2011-12-20
      • 2012-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多