DataTables warning: table id=dataTable - Requested unknown parameter '0' for row 0, column 0. For mo

DataTables warning: table id=dataTable - Requested unknown parameter '0' for row 0, column 0. For mo

brlforbrlfor Posts: 2Questions: 0Answers: 0

Hi everybody. I have seen lots of comments on this issue, but up to now I couldn´t find a way to rid of it. Please check my js file:

var teste;
var http = new XMLHttpRequest();
var url = "../api/getActiveLockout";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/json");

http.onreadystatechange = function() {
//Call a function when the state changes.
if (http.readyState == 4 && http.status == 200) {
//alert(http.responseText);
console.log(http.response);
teste = JSON.parse(http.responseText);
console.log(teste);
console.log(formatIntoArrayOfArray(teste));
$("#dataTable").DataTable({
destroy: true,
data: teste
/columns: [
{ title: "Usina" },
{ title: "Area" },
{ title: "TAG" },
{ title: "Descricao" },
{ title: "Solicitante" },
{ title: "Chapa Solicitante" },
{ title: "Eletricista" },
{ title: "Chapa Eletricista" },
{ title: "Data do Bloqueio" }
]
/
});
}
};
//http.send(params);
http.send();

//#### formata os dados no padrão data=[["dado1","dado2"]] ####
function formatIntoArrayOfArray(arrayData) {
var arrayOfArray = [];
var elementArray = [];
console.log(arrayData.length);
for (let i = 0; i < arrayData.length; i++) {
elementArray[i] = [
arrayData[i].Usina.value,
arrayData[i].Area.value,
arrayData[i].TAG.value,
arrayData[i].Descricao.value.toString(),
arrayData[i].Solicitante.value,
arrayData[i].ChapaSolicitante.value.toString(),
arrayData[i].Eletricista.value,
arrayData[i].ChapaEletricista.value.toString(),
arrayData[i].DataBloqueio.value
];
arrayOfArray[i] = elementArray[i];
}
console.log(arrayOfArray);
return arrayOfArray;
}

$(document).ready(function() {});

Any help will be much appreciated.

Thanks in advance.

Replies

  • brlforbrlfor Posts: 2Questions: 0Answers: 0

    Found the error!

    after formatting my http.request into an array of array, I should have send it to 'teste' variable again. Something like

    teste = formatIntoArrayofArray(teste).

    Now it is working as I expected!

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Thanks for posting back. Good to hear you've got it working now.

    Allan

This discussion has been closed.