I want to load dynamic data into my jQuery datatable. This means that before I get json data from the server, I don't know what fields it contains, but I'm sure json is valid. It will look lower
"data": [ { "first_name": "Airi", "last_name": "Satou", "position": "Accountant", "office": "Tokyo", "start_date": "28th Nov 08", "salary": "$162,700" }, { "first_name": "Angelica", "last_name": "Ramos", "position": "Chief Executive Officer (CEO)", "office": "London", "start_date": "9th Oct 09", "salary": "$1,200,000" }
]
sometimes it can contain only "first_name" and "last_name".
I searched for a long time, all samples indicate "aoColumnsDef" or "aoColumns". But I do not know the exact places. Is there a way to populate a jquery datatable using the field name in json as the table header and the field value as the body of the table? For example, json data contains only two fields: "first_name" and "last_name", the table should contain two columns "first_name" and "last_name". If json contains 3 fields, the table should display 3 columns. I am sure that all elements in the "data" have the same fields.
Thanks in advance!
source share