Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82293

Using row.remove or rows.remove, how do you pass a row ID to ajax to delete the row from mysql

$
0
0

Clicking the Delete button visually deletes the row but not from the database. It passes an Undefined ID to the $ajax postData.php script. html:

<button id="deleteRow"  class="pull-right">Delete selected row</button>

<tr id='57' rowid='57'> // $id or $rowid
  <td><input type='text' class='saveData' value='Donna Snider' name='name' id="57"></td>
  <td><input type='text' class='saveData' value='Customer Support' name='position' id="57"></td>
  <td>$112,000</td>
</tr>

JavaScript:

<script>
$(document).ready(function(){
  var table = $('#example').DataTable();
  $('#example tbody').on( 'click', 'tr', function () {
    if ( $(this).hasClass('selected') ) {
      $(this).removeClass('selected');
    }
    else {
      table.$('tr.selected').removeClass('selected');
      $(this).addClass('selected');
    }
  });

  $('#deleteRow').click( function () {
    var DELETE = "yes";
    var name = $("#name").val();
    var ID=$(this).attr('id');

    table.row('.selected').remove().draw( false ); // visually delete row

    $("#Status").html( "" );
    var dataString = 'delete='+DELETE +'&id='+ID+'&name='+name;
    $.ajax({
      type: "POST",
      url: "postData.php",
      data: dataString,
      cache: false,
      success: function(html) { $("#Result").html( html ); }
    });
  });
});
</script>

Minus the ID problem the code above I think is good for a single row only. How would you make it work so that you can select/delete multiple rows as well? I can provide a demo link if that helps.


Viewing all articles
Browse latest Browse all 82293

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>