Error using JSON with datatable

-3

I'm trying to implement my json using the datatable tool, follow my json :

[
{"Nome":"Felipe","Data":null,"Tipo":"Normal","RG":"123456798"},
{"Nome":"Felipe2","Data":null,"Tipo":"Normal","RG":"123456798"},
{"Nome":"Felipe3","Data":null,"Tipo":"Normal","RG":"123456798"}
]"

set an example in JSFIDDLE url:      link

After this, I would like to know if there is any possibility of leaving the dynamic header, that is, <th></th> of <thead>

Thank you

    
asked by anonymous 04.01.2016 / 14:14

1 answer

2

Follow JsFiddle with the answer: link

Missing <tr> in <thead> in table declaration:

<table class="table table-bordered">
  <thead>
  <tr>
    <th>Nome</th>
    <th>Data</th>
    <th>Tipo</th>
    <th>RG</th>
    </tr>
  </thead>
</table>

And also fix the DataTable constructor

$(document).ready(function() {

  var dataSet = [ {  "Nome": "Felipe",  "Data": "null",  "Tipo": "Normal",  "RG": "123456798"}, {  "Nome": "Felipe2", "Data": "null", "Tipo": "Normal", "RG": "123456798"}, { "Nome": "Felipe3", "Data": "null", "Tipo": "Normal", "RG": "123456798"}];

  $('.table').DataTable({  
     data: dataSet,
        columns: [
            { data: "Nome" },
            { data: "Data" },
            { data: "Tipo" },
            { data: "RG" }
        ] 
    });
});

Follow the DataTables.net documentation with JavaScript datasource .

Here's an example with dynamic columns: link

    
04.01.2016 / 16:16