0

I have created a DataTable in my React project. I am trying to include a serial number column and with my current approach it works as per my requirement for on page load results and pagination. [ 1, 2, 3, 4, 5... ]

The issue is while trying to sort the data based on column (click on column header), it sticks with the old serial number which doesn't look in order. [ 2, 3, 5, 1, 4... ]

The expectation is while sorting by column it should display the serial number in order. [ 1, 2, 3, 4, 5... ]

I have used this approach for displaying serial number.

const columns = [
    {
        title: "S. No.",
        render: function (_data: any, _type: any, _row: any, meta: any) {
            return meta.row + meta.settings._iDisplayStart + 1;
        },
    },
        .
        .
        .
]

How it shows before sorting Without Sorting Serial Number

If sort using Quantity column, serial number gets disturbed. Sorted data serial number

indiedev
  • 21
  • 3
  • If I have understood the problem correctly, you want the `S. No. ` column's data to always have fixed content, regardless of sorting and filtering on the rest of the data. If that is correct, you can use one of the approaches shown in [DataTables How can I add row numbers on a table](https://stackoverflow.com/q/63483618/12567365). (There are 2 different answers with 2 different approaches shown.) – andrewJames Mar 15 '23 at 14:42

0 Answers0