You are here

Display row number per group if table grouped by field

To display the row number generally we can use the views "Global: View result counter (ID)" field in the view but if your view is grouped by
any specific field then it will start displaying the wrong row number. It will show the on the basis of the latest uploaded content.
You can correct this by using PHP and its quite straight forward.
For this you have to create a template inside your theme/templates folders.

1) Name the template
Go to your view -> click on Theme: Information -> Under Style output section, choose a view name which represent your view.
In my case it was a block with name block_1 and view name "document" so i choose " views-view-table--document--block-1.tpl.php" to be
very specific to that block.

2) Create a Global: View result counter (ID) field in your view if you haven't created it.

3) Copy the below code and put it inside your template file.
Below code starts a counter variable and search for "Global: View result counter (ID)" field whose machine name is "counter" and replace it with our counter value. By this way we will get the advantage of displaying all the classes also, which view was already displaying.