Create Json as input to jQuery DataTables
Hello,
I'm attempting to use the "aaData" property of jquery DataTables plugin, but having a problem rendering my table when I pass it a Json formatted variable.
My table does exists in the Html section of the page with id="pftable" , so now I just need to call DataTables like this:
$('#pftable').dataTable()
with the use of the "aaData" property.
It works as follows, but with only one record. I can't however figure out how to ADD to the JsonTest variable :
Copy code
- var JsonTest = { "aaData": [] };
- JsonTest =
- {
- "PfId": "1000",
- "Name": "Bob Jr.",
- "ExpType": "Hs Var",
- "Date": "05/01/1967",
- "Term": "term 123",
- "Exposure": "55,000,000"
- };
- var oTable = $('#pftable').dataTable({
- "aaData": [JsonTest],
- "aoColumns":[
- { "mData": "PfId" },
- { "mData": "Name" },
- { "mData": "ExpType" },
- { "mData": "Date" },
- { "mData": "Term" },
- { "mData": "Exposure" }
- ],
- 'aoColumnDefs': [
- { "sTitle": "Pf Id", "aTargets": [0] },
- { "sTitle": "Name", "aTargets": [1] },
- { "sTitle": "Exp Type", "aTargets": [2] },
- { "sTitle": "Date", "aTargets": [3] },
- { "sTitle": "Term", "aTargets": [4] },
- { "sTitle": "Exposure", "aTargets": [5] },
- ]
- });
The DataTable DOES NOT render when I add records as follows:
Copy code
- JsonTest =
- {
- "PfId": "1000",
- "Name": "Bob Jr.",
- "ExpType": "Hs Var",
- "Date": "05/01/1967",
- "Term": "term 123",
- "Exposure": "55,000,000"
- };
- JsonTest +=
- {
- "PfId": "11000",
- "Name": "James",
- "ExpType": "Hs Var",
- "Date": "06/14/2003",
- "Term": "term 123",
- "Exposure": "56,000,000"
- };
Can someone help me to properly format my Json object so I can ADD records to it, and subsequently render my DataTable ?
thanks.
Bob