I was returning [object object] and now undefined

I was returning [object object] and now undefined

klermannklermann Posts: 277Questions: 67Answers: 1
edited May 2017 in Free community support

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

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    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

  • klermannklermann Posts: 277Questions: 67Answers: 1

    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

  • kthorngrenkthorngren Posts: 21,117Questions: 26Answers: 4,916
    edited May 2017

    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 be mRender. SWidth is sWidth, etc.

    Additionally your Return "'" + data.value + "'"; should be return "'" + data.value + "'";.

    Not sure you want data.value in your render function. You might just want data. You can use console.log(data); within the function to see what data or the other parameters are.

    Kevin

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Dear kthorngren, you did not understand the question and ended up not explaining anything, just confusing me more, the bindrid understood well!

  • kthorngrenkthorngren Posts: 21,117Questions: 26Answers: 4,916

    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:

    Is returning me undefined. What can it be and how can i solve it?

    Do you still have the same question?

    Kevin

  • klermannklermann Posts: 277Questions: 67Answers: 1
    edited May 2017

    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

  • kthorngrenkthorngren Posts: 21,117Questions: 26Answers: 4,916
    edited May 2017 Answer ✓

    That looks better :smile:

    One of your records looks like this:

    {
            "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
            }]
        }
    

    minhasContas is an array with one element that is an object. To access the first element of the array you need to use data[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

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Thanks, thank you very much and Kevin and excuse me for the rudeness.

This discussion has been closed.