本文介绍了如何在dataTable的单个单元格中添加多个json值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在dataTable的单个单元格中添加多个json值。
我正在通过数据表文档,但不能得到一个明确的例子。

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.

我有以下的JSON字符串,我正在通过会话访问它到一个dataTable 。

I have the following JSON string which I am accessing it through a session into a 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>"}

                ]
        });

在我的datatable里LastNam e出现我想要FirtName,Middle Initial,MRN和age。

In my datatable where the LastName appears I want the FirtName, Middle Initial, MRN and age as well.

如何完成如果有人知道这样做的快速方法。

How is that done. If some one knows a quick way to do this.

推荐答案

在DataTables 1.10.x之前,您可以使用参数,如下所示:

Prior to DataTables 1.10.x, you could use the mRender parameter like this:

"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>"}
]

从DataTable 1.10.x开始,您可以使用属性,如这个:

Starting from DataTables 1.10.x, you could use the columns.render property like this:

"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>"}
]

这篇关于如何在dataTable的单个单元格中添加多个json值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 16:26