Get the object in the submitSucess event

Get the object in the submitSucess event

klermannklermann Posts: 277Questions: 67Answers: 1

Hello, how do I get the object in the submitSucess event to return the success message to the user. I tried it in several ways, I tried date [0], date [0] .name, json, etc ...

Answers

  • Tester2017Tester2017 Posts: 145Questions: 23Answers: 17
    edited October 2017

    Boa noite Klermann,

    To return a success message to the user it is up to you. The event 'submitSuccess' is fired when DataTables is receiving a correct JSON response back, without e.g. messages about field validation errors.

    So you can put your customized code inside this event like this:

    editor.on('submitSuccess',  function( e, json, data )
    {
        alert('success');
    })
    

    But instead using an alert it is nicer to use a message area to communicate the success result to the user. This area is not shown but only on success.

    But if you need some data from the returned JSON in your message, like a new generated ID or whatever you can access this by json.data[0].field or json.data[0].table.field depending on how your JSON has been organized.

    I have e.g. a table 'subgroups' with a field 'name' and I can access this by console.log(json.data[0].groups_lc.name);.

    I was only giving an example where you are receiving 1 row back. If there are more rows than you might need to iterate through the JSON response.

  • klermannklermann Posts: 277Questions: 67Answers: 1

    Great Tester2017, good evening! Very good your response. I only need to inform the user when to create, inform the newly created item or even when editing an item inform the edited item, for example the id, item name, etc, or the id and name of the item if it removes it.

  • klermannklermann Posts: 277Questions: 67Answers: 1

    In my case how do I get the values ​​of an object only, as it is coming from all json values ​​ie all objects and I need to get only one, which the user edits, creates or deletes!

This discussion has been closed.