Counter Column

Counter Column

alimbolaralimbolar Posts: 2Questions: 1Answers: 0

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

Answers

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947
    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:
    http://live.datatables.net/guhutepu/1/edit

    Kevin

  • alimbolaralimbolar Posts: 2Questions: 1Answers: 0

    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..:-)..

This discussion has been closed.