Open AndreCabrera opened 6 years ago
id
is the index of the row in the unfiltered dataset, so you could simply use it. Or am I misunderstanding what you want?
I want to do this:
Enumerate all rows automatically, including when filter, add and delete data, is it possible?
What do you want to see when you have filtered data? Something like this?
#| Field1 Field2
1|
3|
4|
6|
If so, you can simply use the id
(maybe id + 1
).
nop, let's suppose to I have 6 rows in my datatable in first time, so when I filtered data (for example this filter get me only 3 rows) I want to see : **
1| 2| 3| I don't want this:
1| 4| 6| Another example: if I have 6 rows in first time and I delete the row 5, I want:
1| 2| 3| 4| 5| I don't want:
1| 2| 3| 4| 6| **
There is no built-in way, but the row are appended to the tbody
element sequentially, so you could simply count the number of tr
in the tbody
, e.g. (not tested):
lineFormat: function (id, data) {
var pageRowNum = $(this).find('tbody tr').length;
var rowNum = (this.getCurrentPage() - 1) * this.options.pageSize + pageRowNum + 1;
// Whatever you want...
}
it works !!, thanks so much.
Hi,
I have a datatable in my project and i can't display the number of row in the first column of my table; how to get the number (position) of any row?
here's my code:
Consider: when delete rows using
$('#myTable').datatable('delete', id);
or add new rows$('#myTable').datatable('insert', json);
the numbers of table rows update automatically, is there a way to do this ?.thanks.