Reputation:
I am new to AngularJs. I am working with ng-grid in AngularJs but I am not able to figure it out how to show serial number or row number in ng-grid.
Upvotes: 4
Views: 7293
Reputation: 2654
I made a plunker that uses ng-grid's 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'}]
};
Upvotes: 2
Reputation: 213
Using {{rowRenderIndex+1}} property, we can easily show serial number in 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%'
}]
Upvotes: 1