I took advantage of your Fiddler of the other issue and I made an amendment based on that new question.
$(document).ready(function() {
var 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"}]';
var column_names = []; //Array com confi das colunas
var jsonObj = JSON.parse(json); //Parse no obj json, facilita o manuseio
//Verifica se tem registro, para nao caga tudo
if(jsonObj.length>0){
//Monta array de colunas
$.each(Object.keys(jsonObj[0]),function(idx,obj){
column_names.push({"sTitle": obj, "mData":obj});
});
$('.table').DataTable({
"aaData": jsonObj,
"aoColumns":column_names
});
}
});
See if it helps you
I have updated your question with dynamic generation of columns.
Hi @Rboscini, thank you for answering, but it was not what I need, there is some way to leave the name of the dynamic column, tipow, only declared ajax, it took the name of the property and set in the column?
– Furlan
Of course you do, but I need to know what you want to do, does each column come with the name json? will come in the correct order, will come in each line, how will you send this data via ajax? send the structure we set up together this
– RBoschini
Let’s take this json as an example:
{ "Nome": "Felipe3", "Data": "null", "Tipo": "Normal", "RG": "123456798"}
my table would automatically have to have the following columns: "Name, Date, Type, RG". That’s the data with your property, you understand? ** will come in the correct order, will come in each line, how you will send this data via ajax? ** A: will come in the correct order, each row is each object, I will not send ajax, just receive– Furlan
changed the Fiddler, take a look.
– RBoschini
Opa @Rboschini, almost there, only she’s being filled
– Furlan
I updated Fiddler, because it gave me -1 ?
– RBoschini
@Rboscihini, man, n know kkkk I clicked up
– Furlan
Let’s go continue this discussion in chat.
– Furlan