Table of Contents
How to add an index column with row numbers in wpDataTables
Say your football league table is sorted by the Position column, and visitors sort it by goals scored to see the best attacks. An index column numbers the rows as they appear on the screen, 1, 2, 3 and so on. After every sort or filter, the numbers start again from 1, so visitors always see the place of each row in the current view.
How do I add an index column?
Turn on Add index column in the Advanced tab and move the column where you want it.
- Open the table settings. Go to wpDataTables → wpDataTables and click the table title.
- Turn on the index column. In the Advanced tab (marked NEW!), turn on Add index column under Index column. After you save, the column is added as the last column.
- Move the column. Click Column List and drag the index column to the first position.
- Save the table. Click Save Changes.
How does the index column count the rows?
The index column counts the rows in the order visitors see them, not in the order of the source:
| What the visitor does | What the index column shows |
|---|---|
| Opens the page | 1, 2, 3 in the default sort order |
| Sorts by another column, for example Goals for | 1, 2, 3 again, in the new order. The team with the most goals is 1. |
| Filters the table, for example to teams with a negative goal difference | 1, 2, 3 for the rows that are left |
What should I remember about the index column?
Turn on Add index column in the Advanced tab, then move the column with the Column List. It always numbers the visible rows from 1, after every sort and filter, so keep fixed ranks as a column in your data.
Where can I read more?
These pages cover sorting and column order: