aenugula karthik
aenugula karthik

Reputation: 359

DataTable Delete row Jquery

I am using datatable plugin for table when I am trying to delete current row, the first row getting delete from datatable and in search also that deleted row shoudnot display

this is my jQuery code:

var table = $('#stockistTable').DataTable();
index = $(this).closest('tr').index();
table.row(index.rowIndex-1).remove().draw( false );

Upvotes: 4

Views: 11284

Answers (5)

aenugula karthik
aenugula karthik

Reputation: 359

  var dtRow=0;  //declare this globally
  dtRow = $(this).closest('tr');  //assigning value on click delete
  var stockistTable=$('#stockistTable').DataTable();
  stockistTable.row(dtRow).remove().draw( false );

This Code worked for me!!!!

Upvotes: 1

colin0117
colin0117

Reputation: 1542

This example here demonstrates how to delete rows from a click event - it should do the trick for you.

Upvotes: -1

Abhilash Ravindran C K
Abhilash Ravindran C K

Reputation: 1856

Following code will be helpful to you,

var table = $('#stockistTable').DataTable();
var index = $(this).closest("tr")[0];
table.fnDeleteRow(table.fnGetPosition(index));

Fiddle Demo Here

Upvotes: 2

Daniyal Nasir
Daniyal Nasir

Reputation: 707

You can make a Jquery object of the entire row element and pass it in row() function of Datatable.

var table = $('#stockistTable').DataTable();
var removingRow = $(this).closest('tr');
table.row(removingRow).remove().draw();

Upvotes: 4

Athul Nath
Athul Nath

Reputation: 2606

You can try this

$(document).ready(function() {
    var table = $('#stockistTable').DataTable();
    $('tr').on("click", function(e) {
       index = $(this).closest('tr').index();
       table.row( $(this) ).remove().draw();
     });
} );

Upvotes: 3

Related Questions