Reputation: 173
I want to get the current datatable row count number that is being edited. Basically, I want to add a row, only if it is the last row in the datatable. Is it possible to get the current absolute index in datatable?
For checking the total number of rows I am using table.rows().count()
Upvotes: 0
Views: 3912
Reputation: 173
Combining both the below answers fixed my issue
<table>
<tr>
<td> asfua</td>
<td> asfua</td>
<td> asfua</td>
<td onclick="Edit(this)"> asfua</td>
</tr>
<tr>
<td> dkbsdf</td>
<td> dkbsdf</td>
<td> dkbsdf</td>
<td onclick="Edit(this)"> dkbsdf</td>
</tr>
</table>
<script>
function Edit(obj) {
console.log(table.row(obj).index());
}
</script>
Upvotes: 0
Reputation: 159
This is easy when you pass this
in you EditFunc(this) and from simple jquery you can get the row index number eg.
<table>
<tr>
<td> asfua</td>
<td> asfua</td>
<td> asfua</td>
<td onclick="Edit(this)"> asfua</td>
</tr>
<tr>
<td> dkbsdf</td>
<td> dkbsdf</td>
<td> dkbsdf</td>
<td onclick="Edit(this)"> dkbsdf</td>
</tr>
</table>
<script>
function Edit(obj) {
console.log($(obj).parent().index())
}
</script>
Data table row index will be consoled of the relative td
Upvotes: 1
Reputation: 927
You can use row().index(); Here is the link: https://datatables.net/reference/api/row().index()
Upvotes: 1