-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGridPremium] Add support for cell selection #6567
Conversation
These are the results for the performance tests:
|
7ed0485
to
6561c62
Compare
At first glance, the selection of multiple cells feels great! |
@joserodolfofreitas I was considering that everything related to clipboard would be done in #199. But I can implement copying the cells here. It will work like the row selection. |
It's fine. It's reasonable to have a separate issue and PR for it, it also reduces the review scope. |
I already added two methods: |
This comment was marked as resolved.
This comment was marked as resolved.
@MatthijsKok Thanks for the feedback! I pushed 7a71703 fixing this. |
rowLength: 10, | ||
maxColumns: 6, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to scroll automatically when selecting cells range?
Currently, using a mouse you can only select cell range within visible cells
Screen.Recording.2022-11-09.at.20.16.22.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of UX, from the sources that I could benchmark:
- Airtable: OK but it feels that it starts scrolling too far away from the bottom of the viewport. It's distracting.
- Google Sheet: OK but it feels that it starts scrolling too late, only once you are beyond the bottom of the viewport. You don't see what you are going to select next.
- Notion: The best 🥇. The threshold feels good, and they also have an incremental scrolling speed based on far you are from the bottom of the viewport 👌.
At least, my perspective as a user, I would be curious about @gerdadesign take on this UX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can implement this later but it's possible. It's similar to what we have for the column headers (although it doesn't work).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's similar to what we have for the column headers (although it doesn't work).
Yes, there's an open issue for it #6236
maxColumns: 6, | ||
}); | ||
|
||
return ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the Shift + Click range selection, is it possible to "remember" the first cell that started the range?
Like in spreadsheet:
Screen.Recording.2022-11-09.at.20.24.24.mov
Currently, the grid creates new range selection started from the last click cell:
Screen.Recording.2022-11-09.at.20.20.49.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the current focus logic, no. The cell with the border is the cell currently focused. When you click the first cell, then the last cell, the focused cell becomes the last clicked one. We would need to split the concept of focused cell between cell that has the focus and cell that has the border. If you create a selection by dragging, not clicking the last cell, then it behaves more like Google Spreadsheet, because the last cell was not clicked and the focus remains in the first cell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We agreed on keeping the current behavior for now, as it requires some changes in how we manage the focused/outlined cell state.
@m4theushw will submit a follow-up PR to change the cell focus management so it's possible to always start a new range from a first selected cell of a previous range.
Did I capture it correctly?
const columnsInRange = visibleColumns.slice(finalStartColumnIndex, finalEndColumnIndex + 1); | ||
|
||
const newModel = rowsInRange.reduce<GridCellSelectionModel>((acc, row) => { | ||
acc[row.id] = columnsInRange.reduce<Record<GridColDef['field'], boolean>>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, the cell selection model keeps track of every selected cell by id + field.
I've noticed a few things related to this:
- you can create a range selection with gaps
- you end up with gaps in range selection after sorting
Maybe we should consider a selection model that has only start and end cell coordinates, where coordinates are row and column indices rather than rowId and column field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can create a range selection with gap
Yes, it's expected. Other spreadsheet apps also allow to start with a range, then use Ctrl to select some cells.
you end up with gaps in range selection after sorting
That's why I prefer to call this feature as "cell selection". Users call select a range of cells, but underneath they are selecting individual cells. I considered only storing the start and end cell coordinates, however, this would bring much more complexity since any cell that is deselected would force a split of the range in many ranges. Also, tracking the selection of individual cells resembles how row selection works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the majority of use cases for cell range selection don't involve sorting and/or filtering, we decided to keep the existing behavior and reconsider it in the future if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great, well done 👌
} from '@mui/x-data-grid-premium'; | ||
import { getBasicGridData } from '@mui/x-data-grid-generator'; | ||
|
||
describe('<DataGridPremium /> - Cell Selection', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sentence case, I think in this case.
describe('<DataGridPremium /> - Cell Selection', () => { | |
describe('<DataGridPremium /> - Cell selection', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were using Pascal case in most cases.
mui-x/packages/grid/x-data-grid-premium/src/tests/rowGrouping.DataGridPremium.test.tsx
Line 64 in 79665e3
describe('<DataGridPremium /> - Row Grouping', () => { |
describe('<DataGridPro /> - Cell Editing', () => { |
describe('<DataGridPro /> - Tree Data', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought is that it seems that can apply https://www.notion.so/mui-org/Style-guide-2a957a4168a54d47b14bae026d06a24b#d8e9cfb2423c4f83844a9f29d2032e3f in these cases.
packages/grid/x-data-grid-premium/src/hooks/features/cellSelection/useGridCellSelection.ts
Outdated
Show resolved
Hide resolved
@@ -84,25 +84,89 @@ The following demo shows the prop in action: | |||
|
|||
{{"demo": "ControlledSelectionServerPaginationGrid.js", "bg": "inline"}} | |||
|
|||
## apiRef [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan) | |||
## Cell selection [<span class="plan-premium"></span>](/x/introduction/licensing/#premium-plan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outside of the scope of this PR (maybe for a follow-up)
It might be better to systematically have premium/pro features on a dedicated page if the section is larger than the viewport. My fear is that a developer might land in the middle of the section using the search without being able to easily see that it's a Pro/Premium feature. With a dedicated page, we get a UX benefit, even in the middle of the page, we see:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do in a follow-up. Since the pages will be split, we also need to add a redirect from /x/react-data-grid/selection/
to /x/react-data-grid/row-selection/
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
This comment was marked as outdated.
This comment was marked as outdated.
Wow! Thanks for the quick response @m4theushw ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
packages/grid/x-data-grid-premium/src/hooks/features/cellSelection/useGridCellSelection.ts
Show resolved
Hide resolved
...ges/grid/x-data-grid-premium/src/hooks/features/cellSelection/gridCellSelectionInterfaces.ts
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid-premium/src/tests/cellSelection.DataGridPremium.test.tsx
Show resolved
Hide resolved
packages/grid/x-data-grid-premium/src/tests/cellSelection.DataGridPremium.test.tsx
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed the behavior when you try and make a new selection when there is already one active can be addressed in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be great to have a list of the next steps once this PR is merged, maybe for new GitHub issues 🤷♂️. Things I'm aware of:
- Move the docs to a separate page to better isolate Pro vs. MIT vs. Premium features [DataGridPremium] Add support for cell selection #6567 (comment)
- Support viewport auto scroll when reaching the edge [DataGridPremium] Add support for cell selection #6567 (comment)
packages/grid/x-data-grid-premium/src/tests/cellSelection.DataGridPremium.test.tsx
Show resolved
Hide resolved
@@ -84,25 +84,89 @@ The following demo shows the prop in action: | |||
|
|||
{{"demo": "ControlledSelectionServerPaginationGrid.js", "bg": "inline"}} | |||
|
|||
## apiRef [<span class="plan-pro"></span>](/x/introduction/licensing/#pro-plan) | |||
## Cell selection [<span class="plan-premium"></span>](/x/introduction/licensing/#premium-plan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great
@MBilalShafi I pushed c3d45b0 fixing the bug you described in #6567 (comment). It only occurs on macOS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
@m4theushw Awesome 👌, great to see this first iteration! Design-wise, the customization demo might look better than the default https://next.mui.com/x/react-data-grid/cell-selection/#customize-range-styling, maybe it should be the default 😁 Default https://codesandbox.io/s/h48tq7?file=/demo.tsx Customization |
Preview: https://deploy-preview-6567--material-ui-x.netlify.app/x/react-data-grid/selection/#cell-selection
Fixes #208
This PR contains the initial implementation of the cell selection feature. The new feature is opt-in, meaning that users need to enable it with the
cellSelection
prop. Both row selection and cell selection can work in parallel, however, using keyboard for selection will lead to different selections. I can't see how this feature will be used in real applications, besides to copy and paste cells, so I didn't implement all equivalent props from row selection here, e.g.isRowSelectable
. This can be done later as we receive feedback from users.