Hi
I have below code but i want to display Sr. No
Code
{{ item.title }}
{{ item.title }}
{{ element[item.name] }}
-->Thanks
Adarsh NigamRank #950 · 2.1K reputationPosted Jul 5, 2024, 5:09 AM EDT
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!!
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts