How to show serial number or line number in Ng grid?

I am new to AngularJs. I am working with ng-grid in AngularJs, but I cannot figure out how to show the serial number or row number in the ng-grid.

+4


source to share


2 answers


I made a planker that uses the ng-grid row.rowIndex property to show the row number in the first column: http://plnkr.co/edit/zLUinDSNUS8B1IrhzYhA?p=preview



 $scope.gridOptions = { 
    data: 'myData',
    columnDefs: [
      {field: '', displayName: 'Row Number', cellTemplate: '<div class="ngCellText ng-scope col1 colt1" ng-class="col.colIndex()"><span ng-cell-text="">{{row.rowIndex + 1}}</span></div>'},
      {field: 'name', displayName: 'Name'}, 
      {field:'age', displayName:'Age'}]
};

      

+2


source


Using the {{rowRenderIndex + 1}} property , we can easily show the serial number in the ng-grid UI.



colDef = [{
      name: 'ID',
      field: '',
      displayName: 'Id',
      cellTemplate: '<span>{{rowRenderIndex+1}}</span>',
      width: '10%'
    }, {
      field: 'data1',
      displayName: 'Data1',
      width: '40%'
    },, {
      field: 'data2',
      displayName: 'Data2',
      width: '40%'
    }]

      

+1


source







All Articles