Get Data From Removed Row

Get Data From Removed Row

Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

I am trying to get some data from the 'postRemove' function after I have deleted a row using the 'Editor Remove' function. Ideally I would like the column 'monitor_id'.

I have tried this but I get nothing in my JSON string,

        editor.on('postRemove', function(e, json, data) {
            $(".refresh-after-ajax").load(window.location + "?delete=true" + " .refresh-after-ajax");
            alert( 'json.cms_module_uptime_monitors.monitor_id' );
        });

I am using a joined table.

What am I doing wrong?

Thanks

Chris

This question has an accepted answers - jump to answer

Answers

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

    Hi Chris,

    The Editor libraries do't bother to return anything in the JSON data to the client-side after a remove since there is nothing needed (normally) there.

    The documentation for remove and postRemove is actually wrong at the moment, there is no data parameter passed into the function. I've just updated this in the repo and will push it out to the site soon.

    Possibly the best option would be to listen for preSubmit and store the id value submitted. Then you can use that in postRemove.

    Regards,
    Allan

  • Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2
    edited March 2015

    I am trying this,

    editor.on('preSubmit', function(e, data, action) {
        alert( 'data.cms_module_uptime_monitors.monitor_id' );
    });
    

    But getting no response, is this not correct? In addition, could you point me in the direction of some documentation which details how to 'store' the id submitted and pass it to postRemove?

    Many thanks

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

    Remove the quotes - at the moment you are just alerting a string! You probably also need data.data.cms_... since that is how the data is structured in the submit.

    The best thing to do would be console.log( data ) and having a look at the console in your browser to inspect the object.

    Allan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited March 2015 Answer ✓

    Oops - missed this bit:

    In addition, could you point me in the direction of some documentation which details how to 'store' the id submitted and pass it to postRemove?

    That more of a general Javascript thing, so not something that is documented in the Editor docs:

    var id;
    
    editor
      .on( 'preSubmit', function ( e, data, action ) {
        id = data.data...;
      } )
      .on( 'postRemove', function ( e, data, action ) {
         ... use id
      } );
    

    Having said that, this isn't actually strict true as Editor doesn't submit any data other than the row id for delete (see the docs here).

    When you noted that it was the id you wanted before I had assumed it was the main row id, not a child id - sorry.

    In which case, what you need to do is something like:

    var id;
    
    editor
      .on( 'preSubmit', function ( e, data, action ) {
        if ( action === 'remove' ) {
          var rowData = table.row( this.modifier() ).data();
          id = rowData.cms_module_uptime_monitors.monitor_id;
        }
      } )
      .on( 'postRemove', function ( e, data, action ) {
         ... use id
      } );
    

    That uses the DataTables API (row().data()) to get the data for the row in question and modifier() to find out what row is in question!

    Allan

  • Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

    Many thanks

This discussion has been closed.