Skip to content

_selectionGridSelectRowWithItem(e, item, index) will send the wrong index when TR index is not the index of the clicked item #64

@alexandru-prigoreanu

Description

@alexandru-prigoreanu

hello! thank you for this great addon.
sometimes we have a problem, please could you check the following and if it makes sense guide us towards a solution? if needed we could also create a PR.

  • we are using Vaadin version 23.4 and selection-grid-flow version 2.0.1
  • we have a SelectionTreeGrid that might show hundreds of nodes when expanded a bit

problem

  • first, on a button click, at the beginning of the tree we expand a parent node P1 with 400 children nodes and select a node (the ui correctly shows the selected node)
  • then, on another button click, at the end of the tree we expand another parent node with 10 children and select the last child node C10 (the ui correctly shows the selected node C10)
  • finally, with mouse click we select the second to last child node C9

what happens

  • in the tree, the selected node is not the clicked one C9, the selected node seems to be one of the children of P1

what was expected instead

  • since we clicked on C9 we expected to see C9 as the selected node

debugging notes

  • the above does not happen when the grid selection mode is SINGLE. it happens 100% of the time when the grid selection mode is MULTI
  • assumption: since there are many nodes in the tree, when the second button is clicked, Vaadin overrides some part of the DOM to keep it light
    • when this happens, the selection-grid-flow assumption that TR index is item index may be wrong in the following selection-grid-flow code
export function _selectionGridSelectRow(e) {
    const vaadinTreeToggle = e.composedPath().find((p) => p.nodeName === "VAADIN-GRID-TREE-TOGGLE");
    if (vaadinTreeToggle) {
        // don't select, it will expand/collapse the node
        // reset the last item
        this.rangeSelectRowFrom = -1;
    } else {
        const tr = e.composedPath().find((p) => p.nodeName === "TR");
        if (tr && typeof tr.index != 'undefined') {
            const item = tr._item;
            const index = tr.index;

            this._selectionGridSelectRowWithItem(e, item, index);
        }
    }
}
  • because Vaadin internals overrode TR content
    • in our case, the user clicked node has real index of 610; the TR index sent to _selectionGridSelectRowWithItem is 209

what are your thoughts on the above?

thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions