Good afternoon ... I need to create a table where rows and columns are created dynamically. For example, consider this JSON:
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
and the JS code
var table = '<div class=\'dataTables\'>';
* table += '<div class=\'table-responsive\'>';
* table += '<table id=\'tabela\' style=\'white-space: nowrap;\' cellspacing=\'0\' width=\'100%\' class=\'table table-hover table-striped table-bordered\'>';
* table += '<thead>';
//criar o cabecalho de acordo com o JSON
table += '</thead>';
* table += '<tfoot><tr class=\'tr-foot\' id=\'tFoot\'></tr></tfoot>';
* table += '<tbody>';
*
* //criar as linhas de acordo com o json
*
* table += '</tbody>'
* table += '</table>';
* table += '</div>';
* table += '</div>';
I'm having a hard time creating the columns, with the headers of them, because I do not know how to read this json in order to check the amount of column and only take the "Header" to put on the table.
obs: I do not want to leave the static columns in the table.