returns in the first column undefined undefined

returns in the first column undefined undefined

klermannklermann Posts: 277Questions: 67Answers: 1

Hello, I'm trying to insert any datatable editor into my json in this format:
And returns in the first column undefined undefined...

{"iTotalRecords":0,"iTotalDisplayRecords":0,"data":[ {"id":1,"descricaoReceita":"Receita 1","dataReceita": "year":2015,"month":"FEBRUARY","dayOfMonth":10,"dayOfWeek":"TUESDAY","era":"CE","dayOfYear":41,"leapYear":false,"monthValue":2,"chronology":{"id":"ISO","calendarType":"iso8601"}},"valorReceita":1000.00,"receitaFixa":false,"receitaFixaQuantidade":1,"receitaFixaTempo":"SEMANAS","repetirLancReceita":false,"repetirPorPeriodo":"SEMANAL","pagamento":false,"addObservacao":"","tipoReceitas":[],"minhasContas":[{"id":4,"nome":"Contas 4","dataAcesso":{"year":2017,"month":"APRIL","dayOfMonth":1,"dayOfWeek":"SATURDAY","era":"CE","dayOfYear":91,"leapYear":false,"monthValue":4,"chronology":{"id":"ISO","calendarType":"iso8601"}},"saldoAnterior":0.00,"saldoAtual":3456.00,"saldoFinal":3652.00,"tipo":"POUPANCA","cor":"#q8qwe5","dashBoard":false}],"etiquetas":[{"id":8,"nome":"Etiqueta 8","minhasReceitas":null}],"cor":"rgb(240, 50, 0, 1)"},{"id":18,"descricaoReceita":"Receita 18","dataReceita":{"year":2015,"month":"JULY","dayOfMonth":2,"dayOfWeek":"THURSDAY","era":"CE","dayOfYear":183,"leapYear":false,"monthValue":7,"chronology":{"id":"ISO","calendarType":"iso8601"}},"valorReceita":456.00,"receitaFixa":false,"receitaFixaQuantidade":1,"receitaFixaTempo":"ANOS","repetirLancReceita":false,"repetirPorPeriodo":"MENSAL","pagamento":false,"addObservacao":"","tipoReceitas":[],"minhasContas":[{"id":1,"nome":"Contas 1","dataAcesso":{"year":2017,"month":"JANUARY","dayOfMonth":1,"dayOfWeek":"SUNDAY","era":"CE","dayOfYear":1,"leapYear":false,"monthValue":1,"chronology":{"id":"ISO","calendarType":"iso8601"}},"saldoAnterior":0.00,"saldoAtual":5600.00,"saldoFinal":2520.00,"tipo":"POUPANCA","cor":"#5d4aas","dashBoard":false}],"etiquetas":[{"id":1,"nome":"Etiqueta 1","minhasReceitas":null}],"cor":"rgb(52, 24, 01, 0.8)"}]}

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,300Questions: 26Answers: 4,769

    I don't understand your problem description. However your JSON string doesn't seem to be in a valid format. You can test it here: https://jsonlint.com/

    Kevin

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Json is valid yes, I tested before sending. Now does other tests here without console has this error: TypeError: f is undefined [Learn more] jquery.dataTables.min.js:
    Folloe the setup:
    `<script type="text/javascript">
    var editor; // use a global for the submit and return data rendering in the examples

    $(document).ready(function() {
        editor = new $.fn.dataTable.Editor( {
            ajax: "/financeiro/receitas/listAll",
            table: "#example",
            idSrc: "id",
            fields: [ {
                   label: "Descrição:",
                   name: "descricaoReceita"
              }, {
                    label: "Data:",
                    name: "dataReceita.year"
              }, {
                    label: "Contas:",
                    name: "minhasContas[0].nome"
              }, {
                    label: "Tipo:",
                    name: "tipoReceitas[0].corTipoReceita"
              }, {
                    label: "Valor:",
                    name: "valorReceita"
                }
            ]
        } );
    
        $('#example').DataTable( {
            dom: "Bfrtip",
            ajax: "/financeiro/receitas/listAll",
            columns: [
                /* { data: "id" }, */
                { data: "descricaoReceita" },
                { 
                    data: "dataReceita"/* ,
                    mRender: function(data){
                        dataDay = data.dayOfMonth;
                        dataObj = data.dayOfMonth + '/' + data.monthValue + '/' + data.year
                        return (dataDay < 10) ? '0' + dataObj : dataObj ;
                    }, */
                },
                {
                    data: "minhasContas[0].nome"/* ,
                    mRender: function (data, type, full){
                       return data[0].nome;
                    },
                    sDefaultContent: '' */
                },
                {
                    data: "tipoReceitas"/*  ,
                    mRender: function (data, type, full){
                       return data[0].corTipoReceita;
                    },
                    sDefaultContent: '' */
                },
                { 
                    data: "valorReceita"/* ,
                    mRender: $.fn.dataTable.render.number('.', ',', 2, 'R$ ') */
                }
            ],
            select: true,
            buttons: [
                { extend: "create", editor: editor },
                { extend: "edit",   editor: editor },
                { extend: "remove", editor: editor }
            ]
        } );
    } );
    
    </script>`
    

    And table:
    <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>id</th> <th>Descrição</th> <th>Data</th> <th>Conta</th> <th>Tipo</th> <th>Valor</th> </tr> </thead> <tfoot> <tr> <th>id</th> <th>Descrição</th> <th>Data</th> <th>Conta</th> <th>Tipo</th> <th>Valor</th> </tr> </tfoot> </table> <table class="table table-hover dataTable table-striped w-full" id="receitasTable"> <thead> <tr> <th>id</th> <th>Descrição</th> <th>Data</th> <th>Etiquetas</th> <th>Conta</th> <th>Tipo</th> <th>Valor</th> </tr> </thead> </table>

  • klermannklermann Posts: 277Questions: 67Answers: 1

    I was able to view the data here

  • kthorngrenkthorngren Posts: 20,300Questions: 26Answers: 4,769
    edited July 2017 Answer ✓

    Json is valid yes, I tested before sending

    When I copy the above JSON into jsonlinit I get the following error:

    Error: Parse error on line 7:
    ...dataReceita": "year": 2015,          "month": 
    -----------------------^
    Expecting 'EOF', '}', ',', ']', got ':'
    

    Which is this at the beginning of the JSON string:

    {
        "iTotalRecords": 0,
        "iTotalDisplayRecords": 0,
        "data": [{
                "id": 1,
                "descricaoReceita": "Receita 1",
                "dataReceita": "year": 2015,
    

    Maybe there was a problem when you pasted it into the thread?

    Maybe you can use the debugger to provide the full JSON response. Also it is helpful if you can format you code blocks using triple ticks (```).

    TypeError: f is undefined [Learn more] jquery.dataTables.min.js

    Are you loading jQuery?

    Kevin

  • klermannklermann Posts: 277Questions: 67Answers: 1

    I was able to load successfully, thanks

This discussion has been closed.