Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

jquery - How to add multiple json values in a single cell of dataTable

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.

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>

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...