Search code examples
angularjssmart-table

How to show row number in Smart Table?


I would like to include the row number of the sorted and filtered dataset in Smart Table as a separate column.

As long as I do not use paging I can simply use the $index propery of angular's ng-repeat but this does not work where paging is enabled since $index starts on 0 for each page.

Anyone have any ideas on how to accomplish this?


Solution

  • I found a way to do this:

    1. Adding the following to the controller
    $scope.page_size = 100
    $scope.current_page = 1
    $scope.rembemberCurrentPage = function(p) {
      $scope.current_page = p
    }
    
    1. Adding the following to the template
    <div st-pagination 
         st-page-change="rembemberCurrentPage(newPage)" 
         st-items-by-page="page_size">
    </div>
    

    3. Row number can then be accessed on the form

    td ng-bind="((current_page-1)*page_size)+$index+1"></td>
    

    I figured it out through this post: https://github.com/lorenzofox3/Smart-Table/issues/438