Is it possible to set row numbers in the kendo angular grid?

2.2k Views Asked by At

I'm using the kendo angular grid to show my data. but I need to have a RowNumber in every row. I searched but did not find any solution to do that. Is it possible to set the row number?

Kendo Angular Grid (documentation)

This is my code :

@Component({
    selector: 'my-app',
    template: `
        <kendo-grid [data]="gridData" [height]="410">
            <kendo-grid-column field="ProductID" title="ID" width="40">
            </kendo-grid-column>
            <kendo-grid-column field="ProductName" title="Name" width="250">
            </kendo-grid-column>
            <kendo-grid-column field="Category.CategoryName" title="Category">
            </kendo-grid-column>
            <kendo-grid-column field="UnitPrice" title="Price" width="80">
            </kendo-grid-column>
            <kendo-grid-column field="UnitsInStock" title="In stock" width="80">
            </kendo-grid-column>
            <kendo-grid-column field="Discontinued" title="Discontinued" width="120">
                <ng-template kendoGridCellTemplate let-dataItem>
                    <input type="checkbox" [checked]="dataItem.Discontinued" disabled/>
                </ng-template>
            </kendo-grid-column>
        </kendo-grid>
    `
})
export class AppComponent {
    public gridData: any[] = products;
}
2

There are 2 best solutions below

1
Ehsan Kiani On BEST ANSWER

You can add a column like this:

            <kendo-grid-column >
                <ng-template kendoGridCellTemplate let-rowIndex="rowIndex">
                   {{rowIndex}} 
                </ng-template>
            </kendo-grid-column>

stackblitz

0
Nitin Gauswami On

You can add column which will start with 1

   <kendo-grid-column title="Serial Number">
        <ng-template kendoGridCellTemplate let-rowIndex="rowIndex">
          {{rowIndex+1}}
       </ng-template>
   </kendo-grid-column>