javascript - jQuery DataTables plugin: add column headers dynamically -


i interested in creating function creates datatables dynamically the data parameter passed in function.

below wrote far, datatables can add rows dynamically, not column header - can use here (i've read dt api, didn't find there).

 var table2 = $('#example2').datatable({         "paging" : true,         "ordering" : true,       });        // header row     table2.columns().header(data["header"]).draw();       // create rows      (var prop in data["staff"]) {         table2.row.add([         data["staff"][prop].name,         data["staff"][prop].position,         data["staff"][prop].office,         data["staff"][prop].age,         data["staff"][prop].start_date,         data["staff"][prop].salary         ]).draw();      } 

the data passed function:

var data = { "header": [     "name",     "position",     "office",     "age",     "start_date",     "salary" ], "staff": [     {         "name": "tiger nixon",         "position": "system architect",         "office": "edinburgh",         "age": 61,         "start_date": "2011/04/25",         "salary": "$320,800"     },     {         "name": "garrett winters",         "position": "accountant",         "office": "tokyo",         "age": 63,         "start_date": "2011/07/25",         "salary": "$170,750"     },     {         "name": "ashton cox",         "position": "junior technical author",         "office": "san francisco",         "age": 66,         "start_date": "2009/01/12",         "salary": "$86,000"     } ] }; 


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -