I am using JQuery DataTables to paint some data in a Modal Window, but, wanting to obtain that same data when validating gives me undefined
, it does not let me insert new columns either, it inserts them as blank fields, I attach the code:
HTML
<div class="col-md-6 offset-md-3">
<table id="Propiedades" class="display projects-table table table-striped table-bordered table-hover" cellspacing="0">
<thead>
<tr>
<th>Propiedad</th>
<th>Valor</th>
</tr>
</thead>
</table>
</div>
javascript
ajax-method:
t = $('#Propiedades').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json"
},
//Obtengo los datos correctamente
"ajax": "/Configuracion/GetPropiedadesArtDataJson/" + $('#Id').val(),
"bDestroy": true,
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json"
}, select: {
style: 'multi'
},
"iDisplayLength": 2,
"columns": [
{ "data": "Propiedad" },
{ "data": "Valor" }
],
"order": [[1, 'asc']],
"fnDrawCallback": function (oSettings) {
runAllCharts();
}
});
Click accept to calculate the data:
var data = t
.rows()
.data();
propi = "";
for (var i = 0; i < data.length; i++) {
//Genero una string y concateno los datos para pasarselo al controlador, aquí es donde me sale undefined
propi += data[i][0] + "{" + data[i][1] + "¬";
console.log(propi);
$('#Datos').val(propi);
}
Testing in the console to see where the data was lost, I verified that when entering the loop it was where they "disappeared" I leave some screenshots of the console:
Data:
Correct property and value
Concatenated String:
why don't you capture me well?
Additional data:
When trying to insert another row with t.row.add([prop,val]).draw(false);
it generates the two columns with empty strings"",""
You are assuming that it
data
is a two-dimensional array, but from what you see in the console it is not, it is an array of objects of the typeSo you would have to access with
data[i].Propiedad
ordata[i].Valor
ordata[i].Nombre