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: Enable row selection event #1018

Closed
CristianDDias opened this issue Dec 4, 2019 · 7 comments · Fixed by #1186
Closed

Table: Enable row selection event #1018

CristianDDias opened this issue Dec 4, 2019 · 7 comments · Fixed by #1186
Assignees

Comments

@CristianDDias
Copy link

This issue is related to this UI5 Web Components React issue.

Is your feature request related to a problem? Please describe.
We are using the Table component but we need to select a table row, which is not possible. We tried to use the AnalyticalTable (UI5 Web Components React) component but it needs a rowHeight props, which is not possible in our case, because the row height can be different for each table row (dynamic height).

Describe the solution you'd like
An onClick callback function for the table row, which is fired when the user selects a table row. This callback function receives as a parameter the selected row.

Describe alternatives you've considered
Access the shadowRoot of the Table web component and add an onClick event listener for each tr element and expose this callback function.

Here is a Codesandbox example about what we would expect from the table (without the onclick feature).

@fifoosid
Copy link
Contributor

fifoosid commented Dec 5, 2019

Hi @CristianDDias

Thanks for the feature request!

I was wondering if you have tried to add event listener for the click event on the ui5-table-row. This way you can use the standard DOM event.

Please let me know if this solution works for you.

Best regards,
Filip

@fifoosid
Copy link
Contributor

fifoosid commented Dec 5, 2019

Here I have made a demo how you can use the DOM event(I think that codesandbox are having troubles right now and CS works on my side only in incognito tab): https://codesandbox.io/s/ui5-table-row-click-event-zm53o

It requires some additional checks to be done, so we will discuss your feature request internally and get back to you with a statement whether this needs to be implemented on our side.

@CristianDDias
Copy link
Author

Hi @fifoosid

I've just tried the idea that you suggested and it worked! Here is the Codesandbox where I tried it.

But I couldn't change the background color of the selected row. In order to achieve this using the UI5 Web Components React, I think that I would need to access the shadow root of the ui5-table-row and change the background color of the tr element. But I think this is not a good idea.

@fifoosid
Copy link
Contributor

fifoosid commented Dec 5, 2019

Hi,

I must point out that what you are trying to achieve is something that is not fiori compliant.

But if you have to stick to that design you have a couple of options:

Go with the approach of accessing the shadow root(just like in the example), which indeed is not a good idea.

If you go with this approach my hint would be to change this selector
row.shadowRoot.firstElementChild
to something like this
row.shadowRoot.querySelector("tr")
because if we change the HTML structure of the ui5-table-row, the first one is more likely to fail

You can use our experimental method called addCustomCss.

In order to use it, you have to import it like this:

import { addCustomCSS } from '@ui5/webcomponents-base/dist/theming/CustomStyle.js';

And then use it:

addCustomCSS("ui5-table-row", `
// css you wish to add
`)

Here you have to make a selector that only matches the selected row(because otherwise it would be applied to all ui5-table-row's), which might be challenging, depending the way you are keeping track of it.

No matter which option you choose, you should have in mind:

  • It might not work on IE11 as expected(It is not a concern, if you are not supporting it)
  • If you have support for more than one theme in your app, you should add css for all your themes
    by yourself.(If you have only 1 team it should work as expected)

@CristianDDias
Copy link
Author

Hi

Why isn't this fiori compliant?

I'll try this addCustomCSS.

By the moment, we won't support IE11 and we only have 1 theme.

@fifoosid
Copy link
Contributor

fifoosid commented Dec 5, 2019

Hi @CristianDDias ,

It's my bad actually, I checked the specs and everything looks fine. 😄
Please let us know if you have any further issues.

In the meantime, I will keep this issue open as a feature request for the click event.

Best regards,
Filip

@CristianDDias
Copy link
Author

Thank you for the help @fifoosid!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants