【问题标题】:Conditional Formatting in Datatables using _TOTAL_使用 _TOTAL_ 的数据表中的条件格式
【发布时间】:2013-04-19 14:35:14
【问题描述】:

最近对Datatables有点烦恼,把oLanguagesInfo属性改成了"There are _TOTAL_ people in this Role."

如果我有 2 个或更多条目,这很好,但在这个表有一个条目的常见情况下,我最终会得到“这个角色有 1 个人” - 看起来很糟糕。

所以我的问题是,有什么方法可以获取_TOTAL_ 属性的值并在 JQuery Datatables 中使用替代字符串?

这是完整的代码示例:

$("#sqepMatrix").dataTable({
        "bJQueryUI": true,
        "bPaginate": false,
        "oLanguage": {
            "sInfo": "There are _TOTAL_ people in this Role."
        },
        "sPaginationType": "full_numbers"
    });

【问题讨论】:

    标签: jquery jquery-ui jquery-plugins datatables


    【解决方案1】:

    我想通了!

    使用 fnInfoCallback 属性我可以评估iTotal 属性,并根据下面显示的 if 语句,我可以决定要吐出什么字符串!

    用法:

    $("#sqepMatrix").dataTable({
        "bJQueryUI": true,
        "bPaginate": false,
    
        "sPaginationType": "full_numbers",
        "fnInfoCallback": function (oSettings, iTotal) {
            if (iTotal == 1) {
                return "There is one person in this Role.";
            }
            else {
                return "There are " + iTotal + " people in the Role.";
            }
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 2017-03-19
      • 2017-06-01
      相关资源
      最近更新 更多