Skip to content

[EuiDataGrid] Add new gridStyle.rowClasses API - #5732

Merged
cee-chen merged 5 commits into
elastic:mainfrom
cee-chen:datagrid/rows-api
Apr 5, 2022
Merged

cee-chen merged 5 commits into
elastic:mainfrom
cee-chen:datagrid/rows-api

Conversation

@cee-chen

@cee-chen cee-chen commented Mar 18, 2022 •

Copy link
Copy Markdown
Contributor

Summary

closes #4401

This PR adds the ability to add specific classes/styling to certain rows, primarily for the purpose of highlighting (e.g. selections, or important row data, etc.), via a new gridStyle.rowClasses prop. The API of this is intentionally meant to be similar to rowHeightsOptions.rowHeights.

Screencaps

screencap

Added a gradient/striped example to show how styling differs from styling each individual cell:

cell stripes

row stripes

Checklist

- [ ] Checked in mobile
- [ ] Checked in Chrome, Safari, Edge, and Firefox
- [ ] Checked for breaking changes and labeled appropriately
- [ ] Checked for accessibility including keyboard-only and screenreader modes
- [ ] Updated the Figma library counterpart

- This sets up us shortly adding a `useEffect` to the row manager file
- mostly copying the control columns example for the selection logic
@cee-chen
cee-chen requested a review from chandlerprall March 18, 2022 18:20
@cee-chen
cee-chen marked this pull request as ready for review March 18, 2022 18:29
@cee-chen
cee-chen requested a review from kertal March 18, 2022 18:29
@cee-chen

cee-chen commented Mar 18, 2022 •

Copy link
Copy Markdown
Contributor Author

Adding @kertal as a reviewer, mostly for feedback on the documentation/developer experience (https://eui.elastic.co/pr_5732/#/tabular-content/data-grid-style-display#grid-row-classes). Hopefully this won't turn out to be more of a hassle to use than setCellProps :)

@cee-chen

Copy link
Copy Markdown
Contributor Author

jenkins test this

@kibanamachine

Copy link
Copy Markdown
Contributor

@chandlerprall chandlerprall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM; pulled & tested locally, including configuring the example to use in-memory sorting & verified the checked rows' & initially-styled row's classnames follow the sort operation.

@cee-chen
cee-chen merged commit 135349f into elastic:main Apr 5, 2022
@cee-chen
cee-chen deleted the datagrid/rows-api branch April 5, 2022 23:13
@rbarszcz

rbarszcz commented Feb 25, 2024 •

Copy link
Copy Markdown

sorry to bring this back up.. but this is not working on v93.1.1, now the rowclasses keep 'pilling up' (even the demo on the datagrid style & display - grid row classes)

class="euiDataGridRow euiDataGridRow--rowClassesDemo euiDataGridRow--rowClassesDemoSelected euiDataGridRow--rowClassesDemoSelected"

when you remove the selection it is not removing the classes, and adding the new one.. it's just pilling it up..

did something change on how to customize row background/colors?

@cee-chen

cee-chen commented Mar 4, 2024

Copy link
Copy Markdown
Contributor Author

@rbarszcz Please don't be sorry, thanks a million for catching this! You're totally right that this bug is happening. I've opened a new issue to track and fix the problem: #7548

@rbarszcz

rbarszcz commented Mar 4, 2024 •

Copy link
Copy Markdown

i'm currently 'reseting' the row className before applying my styles, like so:

const rowClasses = useMemo(() => {
let rowClasses = {};
    data.forEach((r, i) => { 
      let row = document.querySelector(`[data-grid-row-index="${i}"]`);
      if (row !== null) row.className = 'euiDataGridRow';
      if (r.contratado) { rowClasses = { ...rowClasses, [i]: 'euiDataGridRow--rowStatusContratada' }; }
      else {
        if (selecionados.includes(i)) { rowClasses = { ...rowClasses, [i]: 'euiDataGridRow--rowStatusSelecionada' }; }
        else { rowClasses = { ...rowClasses, [i]: 'euiDataGridRow--rowStatusNormal' }; }
      }
    });
    return rowClasses;
  }, [selecionados]);

@cee-chen

cee-chen commented Mar 4, 2024 •

Copy link
Copy Markdown
Contributor Author

@rbarszcz After investigating this bug a bit more, it's actually incredibly specific to the classNames being used.

Until #7548 is merged and is released, if you rename your CSS class from .euiDataGridRow--rowStatusNormal to just .rowStatusNormal, .rowStatusContratada, .rowStatusSelecionada, etc., the problem should fix itself.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[EuiDataGrid] Provide a way to highlight a row

4 participants