I was returning [object object] and now undefined
I was returning [object object] and now undefined
klermann
Posts: 277Questions: 67Answers: 1
Hello from making the implementation suggested in this link https://datatables.net/forums/discussion/31118/cell-shows-object-object for my json that returned in cell [object object] and that now after this implementation
{
MRender: function (data, type, full) {
Return "'" + data.value + "'";
},
SWidth: "200px",
MDataProp: 'resourceA',
SDefaultContent: ''
}
Is returning me undefined. What can it be and how can i solve it?
Also follow my JSON:
{
"draw": 1,
"recordsTotal": 13,
"recordsFiltered": 13,
"data": [{
"descricaoReceita": "Entrada 1",
"dataReceita": "Dec 8, 2016 12:00:00 AM",
"valorReceita": 5000.00,
"receitaFixa": true,
"receitaFixaQuantidade": 1,
"receitaFixaTempo": "SEMANAS",
"repetirLancReceita": false,
"pagamento": true,
"tipoReceitas": [],
"minhasContas": [{
"nome": "Banco A",
"dataAcesso": {},
"saldoAnterior": 100.00,
"saldoAtual": 59782.32,
"saldoFinal": 46423.42
}]
}, {
"descricaoReceita": "Entrada 2",
"dataReceita": "Dec 28, 2016 12:00:00 AM",
"valorReceita": 500.00,
"receitaFixa": false,
"receitaFixaQuantidade": 0,
"repetirLancReceita": true,
"repetirPorPeriodo": "SEMANAL",
"pagamento": true,
"tipoReceitas": [],
"minhasContas": [{
"nome": "Banco A",
"dataAcesso": {},
"saldoAnterior": 100.00,
"saldoAtual": 59782.32,
"saldoFinal": 46423.42
}]
}, {
"descricaoReceita": "Entrada 3",
"dataReceita": "Dec 22, 2016 12:00:00 AM",
"valorReceita": 12.00,
"receitaFixa": false,
"receitaFixaQuantidade": 0,
"repetirLancReceita": false,
"pagamento": true,
"tipoReceitas": [],
"minhasContas": [{
"nome": "Banco A",
"dataAcesso": {},
"saldoAnterior": 100.00,
"saldoAtual": 59782.32,
"saldoFinal": 46423.42
}]
}, {
"descricaoReceita": "Entrada 4",
"dataReceita": "Dec 20, 2016 12:00:00 AM",
"valorReceita": 20.00,
"receitaFixa": false,
"receitaFixaQuantidade": 0,
"repetirLancReceita": false,
"pagamento": true,
"tipoReceitas": [],
"minhasContas": [{
"nome": "Banco A",
"dataAcesso": {},
"saldoAnterior": 100.00,
"saldoAtual": 59782.32,
"saldoFinal": 46423.42
}]
}, {
"descricaoReceita": "Entrada 5",
"dataReceita": "Jan 11, 2017 12:00:00 AM",
"valorReceita": 45.45,
"receitaFixa": false,
"receitaFixaQuantidade": 0,
"repetirLancReceita": false,
"pagamento": true,
"tipoReceitas": [],
"minhasContas": [{
"nome": "Banco A",
"dataAcesso": {},
"saldoAnterior": 100.00,
"saldoAtual": 59782.32,
"saldoFinal": 46423.42
}]
}, {
"descricaoReceita": "Entrada 6",
"dataReceita": "Jan 18, 2017 12:00:00 AM",
"valorReceita": 23.42,
"receitaFixa": false,
"receitaFixaQuantidade": 0,
"repetirLancReceita": false,
"pagamento": true,
"tipoReceitas": [],
"minhasContas": [{
"nome": "Banco A",
"dataAcesso": {},
"saldoAnterior": 100.00,
"saldoAtual": 59782.32,
"saldoFinal": 46423.42
}]
}]
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
First of all, your data structure does not match the data structure used in the thread you linked to so it will not work. Second of all, your return in javascript has a capital R. That will not work. Since your data structure is a little more complicated with child arrays and child objects, we would need to know what you are actually trying to display before we can help
The data from the first screen was an example of how I tried to do that I got here to simplify what I want to show and in my data structure I intend to show the date.My Child.Name
Like bindrid mentioned you are mixing case with your commands. You are using the legacy Datatables (pre 1.10) commands. The legacy commands start with lower case letter(s) followed by an upper case letter at the beginning of each word. You can look here for a comparison of the legacy versus current commands and see case notation used for the legacy commands. For example
MRender
should bemRender
.SWidth
issWidth
, etc.Additionally your
Return "'" + data.value + "'";
should bereturn "'" + data.value + "'";
.Not sure you want
data.value
in your render function. You might just wantdata
. You can useconsole.log(data);
within the function to see whatdata
or the other parameters are.Kevin
Dear kthorngren, you did not understand the question and ended up not explaining anything, just confusing me more, the bindrid understood well!
Sorry did intend to confuse you. Thought your question was this:
Do you still have the same question?
Kevin
I'm implementing this way Of my file and I have undefined return.
{
data: 'minhasContas',
mRender: function (data, type, full){
return "'" + data.nome + "'";
},
sWidth: "200px",
sDefaultContent: ''
}
thanks
That looks better
One of your records looks like this:
minhasContas
is an array with one element that is an object. To access the first element of the array you need to usedata[0]
. I think you need to change your return to this:`return "'" + data[0].nome + "'";
You can see this if you add
console.log(data);
into your mRender function.Kevin
Thanks, thank you very much and Kevin and excuse me for the rudeness.