Hi
I have below code but i want to display Sr. No
{{ item.title }}
{{ item.title }}
{{ element[item.name] }}
Thanks
Adarsh NigamPosted Jul 5, 2024, 9:09 AM
For Displaying a serial number (Sr. No) in your Angular table, you need to add an additional column for the serial numbers. Here’s how you can modify your existing code to achieve this:
-----------------------<><><><><><>-----------------------------------
{{ i + 1 }}
{{ item.title }}
{{ item.title }}
{{ element[item.name] }}
------------------------------<><><><><><><>------------------------------------------------------------
Serial Number Column Definition:
is added specifically for the serial number column.index(i) provided by the*matCellDefdirective to show the serial number. Sinceindexstarts at0,i + 1is used to display 1-based serial numbers.Existing Columns:
*ngFor="let item of columns".*ngIf="item.visible").[matColumnDef]="item.name") and corresponding header and data cells are set up accordingly.item.name).Combining Serial Number Column with Other Columns:
columns.By adding this new column, your table will now include a serial number for each row, starting from 1 and incrementing by 1 for each subsequent row. Hope it helps!!