aws/awsui-documentation

Get index for cell item in Table

Closed this issue · 2 comments

Is it possible to get the index of the current item in the Table component? To be able to do something like this:

          {
            id: "id",
            header: "Id",
            cell: (item, index) => index,
          },

As an example

Hello!

You can inject index into the table items before rendering

const indexed = items.map((item, index) => ({...item, index}))
<Table items={indexed} />

Now you can access it via item.index.

Adding it as a second argument will not be possible, because it conflicts with table sorting. Sorted items change their oder while the indices stay.

Ah awesome, thanks a lot!