How can I cancel a row deleting process from Server ?

How can I cancel a row deleting process from Server ?

apimioapimio Posts: 2Questions: 1Answers: 0

This is my first question here and well, I have a little problem.
I'm using the REST mode to CRUD operation on server, because I use codeIgniter to develop my applications. When I sending a DELETE (remove) request to the server, sometimes, I need to cancel the process, but the problem is that Editor is deleting (virtually) the row. This is my reference code:

  $(document).ready(function() {
    dt_editor = new $.fn.dataTable.Editor( {
        // ajax: "<?php echo site_url($ctrl_table . '/getall/'); ?>",
        ajaxUrl: {
            "create": "POST <?php echo site_url($ctrl_table . '/create'); ?>",
            "edit":   "PUT <?php echo site_url($ctrl_table . '/edit'); ?>",
            "remove": "DELETE <?php echo site_url($ctrl_table . '/remove'); ?>"
        },
        ajax: function ( method, url, data, success, error ) {
              $.ajax( {
                  type: method,
                  url:  url,
                  data: data,
                  dataType: "json",
                  success: function (json, textStatus) {
                      if (json.result===false) {
                        alert(json.message);
                        success( json.data );
                      } else {
                        success( json );
                      }
                  },
                  error: function (jqXHR, exception, thrown) {
                    // alert(dataE.message);
                    var msg = '';
                    if (jqXHR.status === 0) {
                        msg = 'Not connect.\n Verify Network.';
                    } else if (jqXHR.status == 404) {
                        msg = 'Requested page not found. [404]';
                    } else if (jqXHR.status == 500) {
                        msg = 'Internal Server Error [500].';
                    } else if (exception === 'parsererror') {
                        msg = 'Requested JSON parse failed.';
                    } else if (exception === 'timeout') {
                        msg = 'Time out error.';
                    } else if (exception === 'abort') {
                        msg = 'Ajax request aborted.';
                    } else {
                        msg = 'Uncaught Error.\n' + jqXHR.responseText;
                    }
                                              // error( xhr, error, thrown );
                    alert(msg);
                  }
              } );
        },

As you can see I'm controlling te error and success, but I don't now how to cancel row's remove.
I'll apreciate any suggestion ;)

Abraham

This question has an accepted answers - jump to answer

Answers

  • apimioapimio Posts: 2Questions: 1Answers: 0

    Well ... just I did need a little more of research :D .. I found the problem and solution. I found the solution on the Client-Server documentation http://editor.datatables.net/manual/server
    There explain every situation and how you can response with error.

    In my case, I just need to response with and JSON with error message like that:

    $this->render_json(array("error" => $error_msg));

    This line will return a {error:"Error Message from server"} to Editor and then It wil cancel the delection.

    Cheers!

    I hope to be usefull to someone.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    Hi,

    Thanks for posting back with your findings. You are correct, this is currently the only way to stop the client side doing is virtual delete. It currently isn't possible to have it not delete the row, without an error message.

    Regards,
    Allan

This discussion has been closed.