【问题标题】:DataTables sort with mDataProp and fnRender from JSONDataTables 使用来自 JSON 的 mDataProp 和 fnRender 排序
【发布时间】:2012-08-23 17:59:34
【问题描述】:

我正在尝试使用 mDataPropfnRenderbUseRendered 根据 ID 对列进行排序,但显示名称。我看到bUseRendered 已被弃用,API 建议使用mDatamRender,但使用这些我无法在我的列中填充任何数据。这是我的代码,它可以工作,但也不能呈现我想要的:

$(document).ready(function() {
oTable = $('#example').dataTable( {
    "sAjaxSource": "source.php",
    "aaSorting": [],
    "aoColumns": [
        { "mDataProp" : "NameID",
           "fnRender" : "Name",
           "bUseRendered": false},
        { "mDataProp" : "Priority"},
        { "mDataProp" : "Action"}
        ]
    } );
} );

这是我使用 mData 的尝试,但这不会填充我的第一列并给我一个错误弹出窗口。

$(document).ready(function() {
oTable = $('#example').dataTable( {
    "sAjaxSource": "source.php",
    "aaSorting": [],
    "aoColumns": [
        { "mData" : "NameID",
           "mRender" : "Name"},
        { "mDataProp" : "Priority"},
        { "mDataProp" : "Action"}
        ]
    } );
} );

任何想法如何让它显示我的Name,但按NameID排序?

【问题讨论】:

  • 我为fnRender 创建了一个函数来从aData 行中获取"Name"。稍后会发布修复。

标签: jquery json sorting datatables


【解决方案1】:
$(document).ready(function() {
oTable = $('#example').dataTable( {
    "sAjaxSource": "source.php",
    "aaSorting": [],
    "aoColumns": [
        { "mDataProp" : "NameID",
          "bUseRendered" : false,
          "fnRender" : function(oObj) {
                       return oObj.aData["Name"];
                       }
        },
        { "mDataProp" : "Priority"},
        { "mDataProp" : "Action"}
        ]
    } );
} );

【讨论】:

    猜你喜欢
    • 2012-08-19
    • 2014-01-05
    • 2015-03-22
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多