Display row number per group if table grouped by field

Warning message

JQuery Cycle must be installed in order to run the slideshow. Please go to Status Report for instructions.

Primary tabs

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.

/**
 * @file
 * Template to display a view as a table.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $header: An array of header labels keyed by field id.
 * - $caption: The caption for this table. May be empty.
 * - $header_classes: An array of header classes keyed by field id.
 * - $fields: An array of CSS IDs to use for each field id.
 * - $classes: A class or classes to apply to the table, based on settings.
 * - $row_classes: An array of classes to apply to each row, indexed by row
 *   number. This matches the index in $rows.
 * - $rows: An array of row items. Each row is an array of content.
 *   $rows are keyed by row number, fields within rows are keyed by field ID.
 * - $field_classes: An array of classes to apply to each field, indexed by
 *   field id, then row number. This matches the index in $rows.
 * @ingroup views_templates
 */
?>
<?php print $attributes; ?>>
   <?php if (!empty($title) || !empty($caption)) : ?>
     <?php print $caption . $title; ?>
  <?php endif; ?>
  <?php if (!empty($header)) : ?>
    
      
        <?php foreach ($header as $field => $label): ?>
          >
            <?php print $label; ?>
          
        <?php endforeach; ?>
      
    
  <?php endif; ?>
  
    <?php $count = 1;
     foreach ($rows as $row_count => $row): ?>
      >
        <?php foreach ($row as $field => $content): ?>
          <?php print drupal_attributes($field_attributes[$field][$row_count]); ?>>
            <?php if($field == 'counter') {
            	  print $count;
            	}
            	else{
            		print $content;
            	} ?>
          
        <?php endforeach; ?>
      
    <?php $count++;
    endforeach; ?>
  

4) Flush the cache.