I am trying to delete with jQuery a row selecting id="data(Number)" from a datatable how this. That's possible, or id would be better on <tr> tag, instead of <td> tag?
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered">
<thead>
<tr>
<th>Check</th>
<th>Field_1</th>
<th>Field_2</th>
<th>Field_3</th>
</tr>
</thead>
<tbody id="dataTable">
<tr>
<td><input type='checkbox' id='data1'><br></td>
<td>Field_1_Input1</td>
<td>Field_2_Input1</td>
<td>Field_3_Input1</td>
</tr>
<tr>
<td><input type='checkbox' id='data2'><br></td>
<td>Field_1_Input2</td>
<td>Field_2_Input2</td>
<td>Field_3_Input2</td>
</tr>
</tbody>
</table>
Try:
function removerow(number){
$('#data'+number).closest('tr').remove();
}
and then you can call for example removerow(2) to delete row that has the input element with id=data2
DEMO
UPDATE (from comments)
To get also the td elements text within the row with $("#data"+i) try:
$('#data' + number).parent().siblings().each(function () {
console.log($(this).text());
});
DEMO2
try the following -
var oTable = $('#table_id').dataTable();
oTable.fnDeleteRow(oTable.fnGetPosition(selected_tr)); // JQuery dataTable function to delete the row from the table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With