Table does not update itself after 'insert', 'update' or 'delete' entry using editors buttons

Table does not update itself after 'insert', 'update' or 'delete' entry using editors buttons

TommyDTTommyDT Posts: 6Questions: 2Answers: 0
edited April 2022 in Free community support

So the problem is what the header says - "Table does not update itself after 'insert', 'update' or 'delete' entry using editor's buttons". My datatables and their editors use java spring boot backend and request data via ajax. But after I add, edit or delete an entry - the changes only affect DB and data in table remain the same and I have to refresh the page manually.

Here is the github link so you could watch it yourself and help me with resolving the problem

Thanks in advance!

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Does your server script follow the Editor Client / Server protocol, shown here?

    Kevin

  • TommyDTTommyDT Posts: 6Questions: 2Answers: 0

    Yes seems like my server script follows the protocol!

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Use the browser's network inspector tool to verify the responses from the server. Let us know if it looks correct. Maybe post a sample response or two so we can take a look.

    Kevin

  • TommyDTTommyDT Posts: 6Questions: 2Answers: 0
    edited April 2022

    ...

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    According to the docs I posted the response should look similar to this:

    {
        "data": [
            {
                "DT_RowId":   "row_29",
                "first_name": "Fiona",
                "last_name":  "Green",
                "position":   "Chief Operating Officer (COO)",
                "office":     "San Francisco",
                "extn":       "2947",
                "salary":     "850000",
                "start_date": "2010-03-11"
            }
        ]
    }
    

    Note the data is in the data object and the row or rows are in an array.

    Kevin

  • TommyDTTommyDT Posts: 6Questions: 2Answers: 0
    edited April 2022

    Kevin. it is not necessery to have "data" there since I configured dadaSrc option on ajax. Did you watch my project on girhub at all?

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    No I didn't use mvn install or other steps to install the app on my machine.

    it is not necessery to have "data" there since I configured dadaSrc option on ajax

    @allan or @colin can comment on this but the ajax.dataSrc is for Datatables not Editor. The Editor is the one looking for the data. The Server to Client docs state that the Editor expects a JSON response with data and other objects in the response. I'm not familiar with any options to change this. I may be wrong though :smile:

    Kevin

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I haven't had a chance to install the app yet, but yes, Editor will expect data to be returned in the format defined here and that is not effected by ajax.dataSrc in DataTables.

    From your dataSrc option you are returning an array of data only. The problem with that in Editor is that it doesn't allow error information to be returned from the server - e.g. the error or fieldErrors properties can't be defined since it is an array, not a JSON object.

    As such, I'd strongly encourage you to change the response from the server.

    That said, if that isn't possible, you could use a bit of a hack like this:

    editor.on('postSubmit', function (e, json) {
      json.data = json.slice();
    });
    

    We need to modify the json parameter that is passed since that is what Editor will have to work with (we can't return a different value). So this addes a data property onto it with a clone of the array.

    Its a hack, and I don't recommend it - as I said above, return an object to be able to send error information back. But that should work if push comes to shove!

    Allan

  • TommyDTTommyDT Posts: 6Questions: 2Answers: 0

    Thanks you all guys! You helped me!

Sign In or Register to comment.