Skip to content

[EuiDataGrid] Provide a way to highlight a row #4401

Closed

Description

@kertal

Currently, if you want to highlight a row in data grid you've to implement this in each cell like this:

Bildschirmfoto 2020-12-19 um 07 35 49

Bildschirmfoto 2020-12-19 um 07 33 57

It would be convenient and more effective (less operations) if one could do this per row and not per cell. Maybe data grid could provide a callback triggered by each row that allows the user to add / remove CSS classNames? This would be a flexible way to style a whole row.


Similar request was made in #5004:

Context:

I need to style the entire row with a repeated background, styling every cell in the row wouldn't look the same.

Styling the row

Screenshot 2021-08-03 at 17 39 13

Styling every cell

styling every item

Activity

  1. github-actions commented on Jun 21, 2021

    @github-actions

    👋 Hey there. This issue hasn't had any activity for 180 days. We'll automatically close it if that trend continues for another week. If you feel this issue is still valid and needs attention please let us know with a comment.

  2. added
    stale-issue
    on Jun 21, 2021
  3. added and removed
    stale-issue
    on Jun 21, 2021
  4. snide commented on Jun 21, 2021

    @snide
    Contributor

    Still valid. Added a skip check.

  5. claudiopro commented on Nov 22, 2021

    @claudiopro
    Contributor

    Hi @snide, this enhancement would be a boon for Observability (and Discover I guess) to easily show row selection for the document/alert flyout. Would you have an ETA for this?

  6. elizabetdev commented on Nov 22, 2021

    @elizabetdev
    Contributor

    this enhancement would be a boon for Observability (and Discover I guess) to easily show row selection for the document/alert flyout. Would you have an ETA for this?

    CC @constancecchen / @chandlerprall

  7. snide commented on Nov 22, 2021

    @snide
    Contributor

    Now that data grid uses an actual wrapper row, my guess is this should be much easier to add now. I'll leave it to @constancecchen for feedback.

  8. cee-chen commented on Nov 22, 2021

    @cee-chen
    Contributor

    See this conversation also:

    #5285 (comment)

  9. claudiopro commented on Nov 22, 2021

    @claudiopro
    Contributor

    Super! Thank you all @snide @constancecchen @miukimiu 😃

  10. cee-chen commented on Jan 18, 2022

    @cee-chen
    Contributor

    Quick update to this: #5515 incidentally adds the ability to quickly target all cells in a row with the following data attribute(s):

    document.querySelectorAll('[data-gridcell-row-index="0"]'); // Row index from your data array, not affected by sorting or pagination
    document.querySelectorAll('[data-gridcell-visible-row-index="0"]'); // Visible row index of rendered grid, affected by sorting and pagination

    Note that this is primarily a vanilla JS workaround for grabbing cells by row that may help folks in the interim. It doesn't provide a React first-party API/prop for rendering specific rows and does not close out/resolve this issue. It also does not resolve the background image issue in the issue description.

    On that front: while we implemented wrapping row DOM nodes in #5285, the DOM nodes primarily are there for accessibility and don't actually function as wrappers (they render with 0 height and have no actual visible DOM rendering). This is because react-window virtualization library absolutely positions all its cells - updating our added row nodes to have matching positions, height, and width would be a moderate lift. It's doable, but it's not a trivial effort unfortunately and is something that would need to be scoped out/put on the roadmap.

  11. kertal commented on Jan 19, 2022

    @kertal
    MemberAuthor

    Could emotion be used to highlight a row? could we as consumers assign custom ids to rows and then use emotion to make it pretty (or) ugly?

  12. cee-chen commented on Jan 19, 2022

    @cee-chen
    Contributor

    You could do that now currently with CSS and data-attr targets, I don't think emotion would significantly change that lift.

    Unfortunately, one of the specific requests for rows is that styling every cell in a row doesn't work for users who want a repeating background image to not break between cells, e.g.

  13. cee-chen commented on Jan 24, 2022

    @cee-chen
    Contributor

    Me: This is a non-trivial effort
    Also me: I'm bored on a Thursday afternoon, let's see if I can solve the row issue

    Good news @kertal @claudiopro @machadoum - the PR #5555 gets our row DOM working, and from there on it's much easier to implement an API for the desired functionality. Example screencap (the CSS being applied is the .euiMark class):

    rows

    The area where I could use your help/feedback is the API that consumers use to pass custom classes/styling to specific rows. My proposal is adding an API to the current gridStyle prop that looks like this:

    <EuiDataGrid
      // ... required props
      gridStyle={{
        rowClasses: {
          0: 'someClass', // the first row will receive the `someClass` class
          1: 'anotherClass',
          5: 'etc',
        }
      }}
    />

    I tried to keep the data structure intentionally similar to rowHeightsOptions. However, my question for you all is whether this is flexible enough for the use case you are looking for or if you need more than this. Do you need the ability to pass any kind of prop (e.g. data attributes, inline styles, etc.) to rows? Or is just CSS classes sufficient for styling/appearances?

    Quick note - in terms of considering our future move to css-in-js, I believe emotion allows passing in class names via a render prop, so I think you will still be able to use emotion and the class paradigm with this API. LMK if that sounds incorrect to you.

  14. kertal commented on Mar 2, 2022

    @kertal
    MemberAuthor

    @constancecchen will follow up here, looking good 👍

  15. kertal commented on Mar 4, 2022

    @kertal
    MemberAuthor

    Me: This is a non-trivial effort Also me: I'm bored on a Thursday afternoon, let's see if I can solve the row issue

    I scheduled some "boredom" to follow up on EUI issues :)

    Good news @kertal @claudiopro @machadoum - the PR #5555 gets our row DOM working, and from there on it's much easier to implement an API for the desired functionality. Example screencap (the CSS being applied is the .euiMark class):

    rows

    Looking good 👍

    The area where I could use your help/feedback is the API that consumers use to pass custom classes/styling to specific rows. My proposal is adding an API to the current gridStyle prop that looks like this:

    <EuiDataGrid
      // ... required props
      gridStyle={{
        rowClasses: {
          0: 'someClass', // the first row will receive the `someClass` class
          1: 'anotherClass',
          5: 'etc',
        }
      }}
    />

    I tried to keep the data structure intentionally similar to rowHeightsOptions.

    Also looking good 👍

    However, my question for you all is whether this is flexible enough for the use case you are looking for or if you need more than this. Do you need the ability to pass any kind of prop (e.g. data attributes, inline styles, etc.) to rows? Or is just CSS classes sufficient for styling/appearances?

    For me CSS classes work fine, I wouldn't need the flexibility .. if we discover some need for that, you know we can continue that pattern rowStyle, rowAttributes, rowWhatever

    Quick note - in terms of considering our future move to css-in-js, I believe emotion allows passing in class names via a render prop, so I think you will still be able to use emotion and the class paradigm with this API. LMK if that sounds incorrect to you.

    in terms of re-rendering, the most effective way to prevent re-renderings would be to target a row using Emotion , so just adding something like this:

    Discover_-_Elastic

    I guess in terms of EuiDataGrid in Discover I will follow this approach, since it's already possible.
  16. cee-chen commented on Mar 14, 2022

    @cee-chen
    Contributor

    Thanks @kertal! Since no one else has expressed a need for more row customization other than CSS classNames, I'll move ahead with opening a PR with my existing logic for the gridStyle.rowClasses API.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions