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

feat: conditional selectability of grid items #7974

Merged
merged 12 commits into from
Oct 23, 2024

Conversation

sissbruecker
Copy link
Contributor

@sissbruecker sissbruecker commented Oct 15, 2024

Adds a isItemSelectable property that can be configured with a function to conditionally allow or disallow changing the selection state, so both selecting and deselecting, of individual items by the user. Programmatic selection is not affected.

Checkboxes for non-selectable items are either hidden, if they are unselected, or readonly if they are selected. The select all checkbox is hidden as well when conditional selection is used.

Part of #1947

Comment on lines +149 to +151
const isSelectable = this._grid.__isItemSelectable(item);
checkbox.readonly = !isSelectable;
checkbox.hidden = !isSelectable && !selected;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rolf specifically suggested to use this behavior.

packages/grid/src/vaadin-grid-selection-column-mixin.js Outdated Show resolved Hide resolved
packages/grid/src/vaadin-grid-selection-column-mixin.js Outdated Show resolved Hide resolved
@sissbruecker sissbruecker marked this pull request as ready for review October 16, 2024 10:26
@sissbruecker sissbruecker requested review from tomivirkki, vursen and ugur-vaadin and removed request for tomivirkki October 16, 2024 10:27
*
* @type {(item: !GridItem) => boolean}
*/
isItemSelectable: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other similar APIs, such as part name generator or isCellEditable, use a row model instance (see __getRowModel). However that only works if you have a row instance available, whereas this can also be called for items that don't have a rendered row. Not sure if we need to align this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed this and decided to only pass the item. Technically we could construct a row model object from the item itself before passing it to the function, but that would potentially require iterating over all grid caches to figure out the flat row index, or whether an item is a nested one. If we later on want to add support for select all, we'll have to run this function in some way or another over all grid items, at which point this could become a performance issue.

Copy link

@sissbruecker sissbruecker merged commit 2bae93a into main Oct 23, 2024
9 checks passed
@sissbruecker sissbruecker deleted the feat/grid-selectable-provider branch October 23, 2024 11:19
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.6.0.beta1 and is also targeting the upcoming stable 24.6.0 version.

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

Successfully merging this pull request may close these issues.

4 participants