Editor Remove Only works once

Editor Remove Only works once

rdhubbardrdhubbard Posts: 1Questions: 1Answers: 0
edited October 2018 in Free community support

The first Time I press the delete button the row it works but when I click then delete button on another row nothing happens?

   $("#featured-listings-table").on( 'click', 'a.editor_delete', function (e) {
  e.preventDefault();

    editor.message( "Are you sure you want to remove this row?" );
    editor.remove(
          $(this).parents('tr'),
         'Delete listing',
         {
             "label": "Delete",
             "fn": function () {
                 editor.submit()
             },
         }
     );
} );


   editor.on('preSubmit', function (e, data, action) {
    $.ajax({
        type: 'DELETE',
        url: 'URL',
        success : function(json) {
          var table = $("#featured-listings-table").DataTable();

          // Find indexes of rows which have `Yes` in the second column
          var index = table.rows().eq( 0 ).filter( function (rowIdx) {
              return table.cell( rowIdx, 0 ).data() === data.data[1].listing_id ? true : false;
          } );

          table.row(index).remove().draw();

          editor.close()
        },
        error : function(request,error)
        {
          console.log(error)
          editor.close()
          alert("Could not delete listing")
        }
    })
  }

Answers

  • colincolin Posts: 15,236Questions: 1Answers: 2,598

    Hi @rdhubbard ,

    It looks like you're doing something odd in the preSubmit with the Ajax, and removing rows from the table before Editor attempts to. This is likely to confuse Editor since the rows will be vanishing under its feet.

    With Editor, this is needed (see example here), so I'm a little muddled as to whether there's a reason why that code is there.

    Cheers,

    Colin

This discussion has been closed.