How does one add a counter column to a simple datatable like this one .. https://datatables.net/examples/ajax/simple.html
I'd like to number the rows 1 to 10 in the first page and 11 to 20 in the second and so on..
This question has an accepted answers - jump to answer
There are a couple options (maybe more) depending on what you want. If you want to assign a static row counter that doesn't change when the table is sorted or searched you can use columns.render and use the meta parameter to get the row ID. This number will be based on the original order of the data before any sorting.
If you want a dynamic row counter that changes on sort or search you can use rowCallback. You will need to grab an API instance and also use page() and page.len() to determine where to start the row counter.
I build an example to demo both of these:
Thanks Kevin.. that was perfect. I was looking at the first option (columns.render).. I wasn't expecting such a quick and elaborate response.. thanks for this.. really really appreciate it..:-)..
It looks like you're new here. If you want to get involved, click one of these buttons!