I am using Ag-Grid in an angular7 application. I am trying to add a static "SrNo" field to the grid, which basically gives serial number to all rows of the grid ( 1,2,3.... ). I am using sorting, row-pinning and row dragging in the grid. The Sr.No that I want to add should be fixed and should not move when sorting, or dragging or pinning. I tried adding the "Sr.No" as { headerName: 'S No', field: "sNo"} where sNo is is defined as index of the returned object + 1. I am getting the SrNo but its moving with the row contents. Is there anyway I can have the Sr.No as a fixed column.
1 Answers
1
votes
You can add sNo property to the data itself by looping through the row data. This can be done when you receive the data from the server itself or before you set the data to the ag-Grid. rowIndex property of rowNode cannot be used here since you need it to be static which it is not.
rowData.forEach((row, i) => row['sNo'] = i + 1)