Data is duplicated, ie in addition to saving the data sen

Data is duplicated, ie in addition to saving the data sen

klermannklermann Posts: 277Questions: 67Answers: 1

Hello. In the editor when I click the button to save the form data, the form is sent and saved, but in my table the data is duplicated, ie in addition to saving the data sent and duplicate them in the table all other items In the table are also duplicates, as the table updates From the order of ex: 1, 2, 3, 4, 5, 6 looks like this: 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 6 What do I do to prevent this?

Answers

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    Can you show me the JSON that your server is returning when you press the submit button please? If you could also show me the Javascript configuration for your Editor, that would be useful.

    Allan

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

    In my database the data is not duplicated
    .

    My JSON:

    {
        "iTotalRecords": 19,
        "iTotalDisplayRecords": 0,
        "data": [{
            "id": 5,
            "descricaoReceita": "Receita 5",
            "dataReceita": {
                "year": 2017,
                "month": "AUGUST",
                "dayOfMonth": 7,
                "dayOfWeek": "MONDAY",
                "era": "CE",
                "dayOfYear": 219,
                "leapYear": false,
                "monthValue": 8,
                "chronology": {
                    "id": "ISO",
                    "calendarType": "iso8601"
                }
            },
            "valorReceita": 5000.00,
            "receitaFixa": true,
            "receitaFixaQuantidade": 0,
            "receitaFixaTempo": "SEMANAS",
            "repetirLancReceita": false,
            "repetirPorPeriodo": "SEMANAL",
            "pagamento": false,
            "addObservacao": "dgdg",
            "tipoReceitas": [{
                "id": 3,
                "nome": "Tipo 3",
                "corTipoReceita": "#AXVXDE",
                "nomeTipoReceita": "Tipo 3"
            }],
            "minhasContas": [{
                "id": 7,
                "nome": "Contas 7",
                "dataAcesso": {
                    "year": 2017,
                    "month": "MAY",
                    "dayOfMonth": 1,
                    "dayOfWeek": "MONDAY",
                    "era": "CE",
                    "dayOfYear": 121,
                    "leapYear": false,
                    "monthValue": 5,
                    "chronology": {
                        "id": "ISO",
                        "calendarType": "iso8601"
                    }
                },
                "saldoAnterior": 0.00,
                "saldoAtual": 4564.00,
                "saldoFinal": 6320.00,
                "tipo": "POUPANCA",
                "cor": "#424345",
                "dashBoard": false
            }],
            "etiquetas": [{
                "id": 4,
                "nome": "Etiqueta 4",
                "minhasReceitas": null
            }],
            "cor": "rgb(143, 1, 225, 1)"
        }, {
            "id": 6,
            "descricaoReceita": "Receita 4545",
            "dataReceita": {
                "year": 2017,
                "month": "AUGUST",
                "dayOfMonth": 7,
                "dayOfWeek": "MONDAY",
                "era": "CE",
                "dayOfYear": 219,
                "leapYear": false,
                "monthValue": 8,
                "chronology": {
                    "id": "ISO",
                    "calendarType": "iso8601"
                }
            },
            "valorReceita": 5000.00,
            "receitaFixa": true,
            "receitaFixaQuantidade": 1,
            "receitaFixaTempo": "MESES",
            "repetirLancReceita": false,
            "repetirPorPeriodo": "QUINZENAL",
            "pagamento": false,
            "addObservacao": "dgdg",
            "tipoReceitas": [],
            "minhasContas": [{
                "id": 6,
                "nome": "Contas 6",
                "dataAcesso": {
                    "year": 2017,
                    "month": "MAY",
                    "dayOfMonth": 1,
                    "dayOfWeek": "MONDAY",
                    "era": "CE",
                    "dayOfYear": 121,
                    "leapYear": false,
                    "monthValue": 5,
                    "chronology": {
                        "id": "ISO",
                        "calendarType": "iso8601"
                    }
                },
                "saldoAnterior": 0.00,
                "saldoAtual": 4564.00,
                "saldoFinal": 1234.00,
                "tipo": "OUTROS",
                "cor": "#ccc545",
                "dashBoard": false
            }],
            "etiquetas": [{
                "id": 3,
                "nome": "Etiqueta 3",
                "minhasReceitas": null
            }],
            "cor": "rgb(255, 128, 0, 0.9)"
        }, {
            "id": 7,
            "descricaoReceita": "Receita 7",
            "dataReceita": {
                "year": 2016,
                "month": "JULY",
                "dayOfMonth": 9,
                "dayOfWeek": "SATURDAY",
                "era": "CE",
                "dayOfYear": 191,
                "leapYear": true,
                "monthValue": 7,
                "chronology": {
                    "id": "ISO",
                    "calendarType": "iso8601"
                }
            },
            "valorReceita": 4567.00,
            "receitaFixa": false,
            "receitaFixaQuantidade": 0,
            "receitaFixaTempo": "SEMANAS",
            "repetirLancReceita": false,
            "repetirPorPeriodo": "ANUAL",
            "pagamento": false,
            "addObservacao": "dgdg",
            "tipoReceitas": [],
            "minhasContas": [{
                "id": 5,
                "nome": "Contas 5",
                "dataAcesso": {
                    "year": 2017,
                    "month": "JUNE",
                    "dayOfMonth": 1,
                    "dayOfWeek": "THURSDAY",
                    "era": "CE",
                    "dayOfYear": 152,
                    "leapYear": false,
                    "monthValue": 6,
                    "chronology": {
                        "id": "ISO",
                        "calendarType": "iso8601"
                    }
                },
                "saldoAnterior": 0.00,
                "saldoAtual": 7897.00,
                "saldoFinal": 4564.00,
                "tipo": "POUPANCA",
                "cor": "#q4weq5",
                "dashBoard": false
            }],
            "etiquetas": [{
                "id": 2,
                "nome": "Etiqueta 2",
                "minhasReceitas": null
            }],
            "cor": "rgb(143, 0, 0, 1)"
        }, {
            "id": 8,
            "descricaoReceita": "Receita 8",
            "dataReceita": {
                "year": 2016,
                "month": "AUGUST",
                "dayOfMonth": 2,
                "dayOfWeek": "TUESDAY",
                "era": "CE",
                "dayOfYear": 215,
                "leapYear": true,
                "monthValue": 8,
                "chronology": {
                    "id": "ISO",
                    "calendarType": "iso8601"
                }
            },
            "valorReceita": 7897.00,
            "receitaFixa": false,
            "receitaFixaQuantidade": 0,
            "receitaFixaTempo": "SEMANAS",
            "repetirLancReceita": false,
            "repetirPorPeriodo": "SEMANAL",
            "pagamento": false,
            "addObservacao": "dgdg",
            "tipoReceitas": [{
                "id": 6,
                "nome": "Tipo 6",
                "corTipoReceita": "#FDSFKK",
                "nomeTipoReceita": "Tipo 6"
            }],
            "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": 1,
                "nome": "Etiqueta 1",
                "minhasReceitas": null
            }],
            "cor": "rgb(50, 90, 100, 0.9)"
        }, {
            "id": 9,
            "descricaoReceita": "Receita 9",
            "dataReceita": {
                "year": 2016,
                "month": "MAY",
                "dayOfMonth": 2,
                "dayOfWeek": "MONDAY",
                "era": "CE",
                "dayOfYear": 123,
                "leapYear": true,
                "monthValue": 5,
                "chronology": {
                    "id": "ISO",
                    "calendarType": "iso8601"
                }
            },
            "valorReceita": 3123.00,
            "receitaFixa": false,
            "receitaFixaQuantidade": 1,
            "receitaFixaTempo": "DIAS",
            "repetirLancReceita": false,
            "repetirPorPeriodo": "MENSAL",
            "pagamento": false,
            "addObservacao": "dgdg",
            "tipoReceitas": [{
                "id": 5,
                "nome": "Tipo 5",
                "corTipoReceita": "#AFFJKL",
                "nomeTipoReceita": "Tipo 5"
            }],
            "minhasContas": [],
            "etiquetas": [{
                "id": 10,
                "nome": "Etiqueta 10",
                "minhasReceitas": null
            }],
            "cor": "rgb(255, 24, 01, 0.8)"
        }]
    }
    

    code editor:

    editor = new $.fn.dataTable.Editor( {
                        ajax: ,
                         {dataType: "JSON",
                            headers: { "X-CSRF-TOKEN": token },
                            contentType: 'application/json',                        
                            data: function ( d ) {
                            var obj;
                            for (var key in d.data) {
                                obj = d.data[key];
                                break;
                            }
                            return JSON.stringify( obj );
                        },
                            create: {type:"POST",
                                url: "/financeiro/receitas/listAll"
                            },
                            edit: { type: "POST",
                                url:  "/financeiro/receitas/listAll_id_"|
                            },
                            remove: { type: "POST",
                                url: "/financeiro/receitas/listAll_id_"
                            }
                        }, 
                        table: "#receitasTable",
                        template: '#form-group-editor',
                        idSrc: "id",
                        fields: [ { name: "descricaoReceita",
                               attr:  {
                                  placeholder: 'Descrição da receita'
                               }
                          }, { name: "dataReceita",
                                type:   'datetime',
                                dateFormat: 'dd/mm/yyyy',
                                attr:  {
                                   maxlength: 50,
                                   placeholder: 'Data da receita'
                                },
                                //fieldInfo: 'Info'
                          },
                          { name: "valorReceita",
                                type: "mask",
                                mask: "###.###.###,00",
                                maskOptions: {
                                  reverse: true,
                                  placeholder: "Valor"
                                }
                          },
                          {label: "Pagar?",
                                name: "receitaFixa",
                                type: "todo",
                                def: 0
                          },
                          { name: "receitaCor",
                                attr:  {
                                      placeholder: 'Atribua uma cor'
                                }
                          },
                          { name: "minhasContas",
                                placeholder: 'Contas',
                                "type": "select",
                                "options": [
                                    "Conta 1",
                                    "Conta 2",
                                    "Conta 3"
                                ],
                                
                          }, { name: "tipoReceitas",
                                placeholder: 'Tipo de receitas',
                                "type": "select",
                                "options": [
                                    "Tipo de receita 1",
                                    "Tipo de receita 2",
                                    "Tipo de receita 3"],
                          },
                          {  name: "receitaFixaQuantidade",
                                attr:  {
                                    placeholder: 'Receita fixa'}
                          },
                          { name: "receitaFixaTempo",
                                attr:  {
                                    placeholder: 'Lançamento por período' }
                          },
                          { name: "etiquetas",
                                attr:  {
                                    placeholder: 'Etiqueta'}
                          },
                          { name: "addObservacao",
                                type:  "textarea",
                                attr:  {
                                    placeholder: 'Adicionar observação'}
                          }
                        ]
                    } );
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    That JSON is what is returned in response to the edit or create action? If so, that is the issue - since it should only be returning the JSON for the newly created row or the edited row(s).

    Full documentation for the client / server interchange is available here.

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Allan, now I only have the object created and returned by json, but it was not updated without date, ie I created the object and the server returned me the json with the created object the datatable did not update, can you give me a suggestion?

    Return of the object:
    {"iTotalRecords":24,"iTotalDisplayRecords":0,"dataReceitas":null,"data":[{"id":176,"descricaoReceita":"Receita Demo","dataReceita":{"year":2017,"month":"AUGUST","dayOfMonth":8,"dayOfWeek":"TUESDAY","era":"CE","dayOfYear":220,"leapYear":false,"monthValue":8,"chronology":{"id":"ISO","calendarType":"iso8601"}},"valorReceita":5000.00,"receitaFixa":true,"receitaFixaQuantidade":null,"receitaFixaTempo":null,"repetirLancReceita":false,"repetirPorPeriodo":null,"pagamento":false,"addObservacao":"Add","tipoReceitas":[],"minhasContas":[],"etiquetas":[],"cor":null}]}

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    Can you give me a link to the page so I can help to debug it.

    Thanks,
    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1

    I am working locally with java, there is no way to pass a link, unfortunately!

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    I'm afraid there isn't a huge amount I can do to offer help in that case. I would need to be able to debug the page to understand what is going wrong as I don't see that in any of my examples, unless you are able to give me a link to an example which is showing the problem.

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Hello Allan, I'm afraid the problem is when I create a new item for the datatable and it is not being updated automatically because the data value is as dataReceit. Would that be my problem?

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Hello Allan,
    I inserted this function to give a reload to the table, now how do I give a highlights in the row inserted in the table

    editor.on( 'postCreate', function ( e, json, data) { oTable.ajax.reload(); } );

  • allanallan Posts: 61,864Questions: 1Answers: 10,136 Site admin

    If you are reloading the table, the old rows are being deleted and new rows being added - which means its actually very difficult to highlight the edited row since you need to find it in the table.

    Instead, I would suggest you change the data being return from the edit action to that required by Editor. Specifically use data rather than dataReceit and make it an array.

    Allan

This discussion has been closed.