Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 390
patz Avatar asked Aug 06 '13 13:08

patz


People also ask

How do I put multiple data in a DataTable column?

columnDefs = [ { data: {name : "name", email : "email", address : "address"}, mRender : function(data, type, full) { return data.name+' '+data. email+' '+data. address; } } ]; The above code can render multiple data in a column of a datatable.

How many rows can Datatables handle?

The maximum number of rows that a DataTable can store is 16,777,216.


1 Answers

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>"}
]
like image 121
tduchateau Avatar answered Oct 23 '22 01:10

tduchateau