Item does not update automatically

Item does not update automatically

klermannklermann Posts: 277Questions: 67Answers: 1

Hello Allan, I am having a problem when I create an item in the datatable, the item is sent to the server normally and created, but it is not updated in the table normally, having to refresh the page to update the item, where is the error in that situation?

login: klermann@hotmail.com
pass: 12345

ec2-34-227-195-94.compute-1.amazonaws.com:8080/financeiro/despesas/

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    I went to the link provided but not sure what steps to recreate the problem. The Editor is expecting the server to send back the created row, like this request/response in the docs:
    https://editor.datatables.net/manual/server#Create

    What is your server script returning?

    Kevin

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

    Hi,

    Could you try adding rowId: 'id' to your DataTables configuration in configDespesas.js please?

    Allan

  • klermannklermann Posts: 277Questions: 67Answers: 1

    This is returning the json of the item that is created or edited, just a single item!

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Hello Allan, there was no change with the addition of the rowId: "id"

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

    Ah - I've got it this time. The problem is indeed in the data that is being returned - Editor expects data to be an array of row objects. Currently you just have an object:

    {
        "iTotalRecords": 0,
        "iTotalDisplayRecords": 0,
        "data": {
            "id": 1,
            "descricaoDespesa": "Despesa 1",
            "dataDespesa": {
                "year": 2018,
                "month": "FEBRUARY",
                "monthValue": 2,
                "dayOfMonth": 8,
                "hour": 10,
                "minute": 26,
                "second": 9,
                "nano": 0,
                "dayOfWeek": "THURSDAY",
                "dayOfYear": 39,
                   ...
        }
    }
    

    It should be:

    {
        "iTotalRecords": 0,
        "iTotalDisplayRecords": 0,
        "data": [ {
            "id": 1,
            "descricaoDespesa": "Despesa 1",
            "dataDespesa": {
                "year": 2018,
                "month": "FEBRUARY",
                "monthValue": 2,
                "dayOfMonth": 8,
                "hour": 10,
                "minute": 26,
                "second": 9,
                "nano": 0,
                "dayOfWeek": "THURSDAY",
                "dayOfYear": 39,
                   ...
        } ]
    }
    

    Allan

This discussion has been closed.