Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table : Set row id #1647

Closed
mathieu-fournier opened this issue Oct 20, 2023 · 9 comments
Closed

Table : Set row id #1647

mathieu-fournier opened this issue Oct 20, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@mathieu-fournier
Copy link

I would like to be able to set a custom id for my table rows.
Ex:
image

Current workaround:
Trick typescript by extanding the GetRowProps class manually.
image

@mathieu-fournier mathieu-fournier added the enhancement New feature or request label Oct 20, 2023
@r100-stack
Copy link
Member

You can use the getRowId prop to set the custom row ids.

<Table
  ...
  getRowId={(row) => row.productId}
/>

You can find all other Table props on our Table documentation page (WIP).

@r100-stack r100-stack closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2023
@mathieu-fournier
Copy link
Author

mathieu-fournier commented Oct 23, 2023

The getRowId prop is not working.
I made a minimal codesandbox :
https://codesandbox.io/s/table-getrowid-notworking-hyr35w?file=/src/App.tsx

I added the getRowId props, but the row has no Id :
image

@r100-stack
Copy link
Member

Actually, upon testing it myself, I noticed no type error when trying to do this. I made a codesandbox for this.

In the sandbox, on L95, we are modifying the internal row id using getRowId. Then on L83, we are setting the HTML id to the internal row id that we set using getRowId.

After discussing over DMs, looks like there was some confusion between getRowId that modifies the internal data ids and rowProps's id that sets the HTML div id. Our Table documentation page is WIP. We will document the difference between them when we work on that page. You can track our documentation progress in #961

@mathieu-fournier
Copy link
Author

From a user perspective.
rowProps sets the html element properties.
I would also expect getRowId to set the html element id.

@mathieu-fournier
Copy link
Author

mathieu-fournier commented Oct 30, 2023

@rohan-kadkol
Also, I did not found a way to add an id to expander button :
image

This makes writing tests less trivial.
I suggest that the expander button sets it's own id based on the row id.
Ex:
id="'custom row id'-expander-button"

@mayank99
Copy link
Contributor

you could use aria-expanded that gets set on the row expander button

@mathieu-fournier
Copy link
Author

mathieu-fournier commented Oct 30, 2023

aria-expanded is present on every rows, it does not help to select and click a specific expander button.
Currently, I must do document traversal to get a specific expander button, which is flaky by nature.
Example :

const myRow = $('#customRowId');
const myExpander = myRow.prev('.iui-table-row-expander');    // Jquery traversal to get a previous sibling.

@mayank99
Copy link
Contributor

you can find the first instance of aria-expanded inside the row (since you already have the row id):

$(`#${rowId} [aria-expanded]`)

https://codesandbox.io/s/sparkling-water-683j53?file=/src/App.tsx

i don't think it makes sense to add ids to expander buttons by default, but we could theoretically support passing a custom id to the expander buttons if you have ideas on a comfortable API.

@mathieu-fournier
Copy link
Author

I added a id to my cell, not the row. my bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants