如何在dataTable的单个单元格中添加多个json值。 我正在阅读数据表文档,但无法得到一个明确的例子。
我有以下JSON字符串,我通过会话将其访问到dataTable。
<textarea id="Report" type="text" style="" name="Report">
[
{
"Identifier": "0",
"LastName": "Cooper",
"FirstName": "Benny",
"MiddleInitial": "P",
"MRN": "7854753",
"Age": "30",
"Gender": "Female",
"Location":
{
"Bed": "1",
"Room": "A",
"unit": "NU1",
"facility": "Fac1"
},
"ServiceDate":"05/03/2013",
"ChargeAndDx":"99222 - 410.01,428",
"BillingProvider":"Palmer, James",
"title":"Add",
"start":"2013-08-07",
"url":"#",
"textColor":"red"
}] </textarea>
我在数据表中访问会话的另一个页面上的是:
$(document).ready(function (){
var ReportData=JSON.parse(document.getElementById("Report").innerHTML);
Report=$('#patientDataTables').dataTable
({
"bJQueryUI":true,
"bScrollCollapse":true,
aaData:patientReportData,
"aoColumns":
[ {"mData":"LastName","sClass":"left"},
{"mData":"ServiceDate","sClass":"left"},
{"mData":"ChargeAndDx","sClass":"left"},
{"mData":"BillingProvider","sClass":"left"},
{"mData":"null","sClass":"center","sDefaultContent":"<a href='' class='editor_menu'>menu</a>"}
]
});
在我的数据表中,LastName出现,我想要FirtName,Middle Initial,MRN和age。
这是怎么做到的。如果有人知道一个快速的方法来做到这一点。
答案 0 :(得分:30)
在DataTables 1.10.x之前,您可以使用mRender参数,如下所示:
"aoColumns":[
{"mData":"LastName",
"sClass":"left",
"mRender":function(data, type, full){
return full.FirstName + full.LastName + full.MiddleInitial;
}
},
{"mData":"ServiceDate","sClass":"left"},
{"mData":"ChargeAndDx","sClass":"left"},
{"mData":"BillingProvider","sClass":"left"},
{"mData":"null","sClass":"center","sDefaultContent":"<a href='' class='editor_menu'>menu</a>"}
]
从DataTables 1.10.x开始,您可以使用columns.render属性,如下所示:
"columns":[
{"data":"LastName",
"className":"left",
"render":function(data, type, full, meta){
return full.FirstName + full.LastName + full.MiddleInitial;
}
},
{"data":"ServiceDate","sClass":"left"},
{"data":"ChargeAndDx","sClass":"left"},
{"data":"BillingProvider","className":"left"},
{"data":"null","className":"center","defaultContent":"<a href='' class='editor_menu'>menu</a>"}
]