jQuery 如何在dataTable的单个单元格中添加多个json值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18081967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add multiple json values in a single cell of dataTable
提问by patz
How to add multiple json values in a single cell of dataTable. I am going through the datatables documentation but cant get a clear example.
如何在dataTable的单个单元格中添加多个json值。我正在浏览数据表文档,但无法得到一个明确的例子。
I have the following JSON string which I am accessing it through a session into a dataTable.
我有以下 JSON 字符串,我通过会话将其访问到数据表中。
<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>
on the other page where I am accessing the session in the datatable is aas follows:
在我访问数据表中的会话的另一个页面上,如下所示:
$(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>"}
]
});
In my datatable where the LastName appears I want the FirtName, Middle Initial, MRN and age as well.
在我的姓氏出现的数据表中,我还需要名字、中间名首字母、MRN 和年龄。
How is that done. If some one knows a quick way to do this.
那是怎么做的。如果有人知道一种快速的方法来做到这一点。
回答by tduchateau
Prior to DataTables 1.10.x, you could use the mRenderparameter like this:
在 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>"}
]
Starting from DataTables 1.10.x, you could use the columns.renderproperty like this:
从数据表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>"}
]