Firstly, create a template field on the table by clicking the ‘Add Field(s)’ dropdown on the table. You can label the template field anything you want.
In the template use:
<span class="counter"></span>
And make sure ‘Allow HTML’ is selected.
Then, add an inline snippet with the following code:
This won’t work, however, for tables with multiple pages or where you are allowing the user to load more data into the table. That would require a different approach - and probably a better one!
There is a really simple, declarative approach that requires NO javaScript code: add a Template column to your Table with the following as its template value:
{{index}}
This is leveraging the {{index}} row merge variable which is available in row merge contexts.