jquery – 如何在dataTable的单个单元格中添加多个json值

前端之家收集整理的这篇文章主要介绍了jquery – 如何在dataTable的单个单元格中添加多个json值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在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>

在另一个页面上,我正在访问datatable中的会话是如下:

$(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",{"mData":"ChargeAndDx",{"mData":"BillingProvider",{"mData":"null","sClass":"center","sDefaultContent":"<a href='' class='editor_menu'>menu</a>"}

                ]
        });

在我的数据表中出现LastName,我想要FirtName,Middle Initial,MRN和age.

怎么做如果有人知道这样做的快速方法.

解决方法

在DataTables 1.10.x之前,您可以使用 mRender参数:
"aoColumns":[   
   {"mData":"LastName","sClass":"left","mRender":function(data,type,full){
       return full.FirstName + full.LastName + full.MiddleInitial;
    }
   },"sDefaultContent":"<a href='' class='editor_menu'>menu</a>"}
]

从DataTables 1.10.x开始,您可以使用这样的columns.render属性

"columns":[   
   {"data":"LastName","className":"left","render":function(data,full,Meta){
       return full.FirstName + full.LastName + full.MiddleInitial;
    }
   },{"data":"ServiceDate",{"data":"ChargeAndDx",{"data":"BillingProvider","className":"left"},{"data":"null","className":"center","defaultContent":"<a href='' class='editor_menu'>menu</a>"}
]

猜你在找的jQuery相关文章