silevis / reactgrid

Add spreadsheet-like behavior to your React app

Home Page:https://reactgrid.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a possibility to set selection ?

icyhot12 opened this issue · comments

What I need is to set selection of the whole row from the right click context menu but I don't see any function to set selection with passing arguments like (row, first column, last column).

There is a similar function "enableRowSelection" but I don't want to select whole row by clicking first cell of the row but with option from right context menu on every available cell.

@icyhot12 What is this application scenario? Can it not be solved through the custom menu of the business side?

What do you mean by that "Can it not be solved through the custom menu of the business side?" ??

I have react app with react-grid implementation, and some users don't want to use enableRowSelection functionality because they can't select only first cell of any row (because with this prop enabled it is selecting whole row) so I am trying to add this functionality from right click context menu as you can see on the screenshot:

image

And it is almost working because the row is selected, but now I have problem when trying to copy the row to clipboard, when pressing cmd + C - nothing is copied, clipboard is empty.
Any ideas ?

I am setting selection of the row with reference to ReactGrid component, sth like that:
spreadSheetRef.current.spreadSheet.current.updateState(state => ({ ...state, selectionMode: "row", selectedIds: [pointetRowId] }))

Row is selected properly, but nothing is copied to clipboard.
edit: I think that this could be a problem with wrong focus after clicking option from context menu

I can't recreate your issue. Are you using v4.1.3?

I was using v4.0.5 but right now I raised version to v4.1.3 and the problem is still occurring.
What is your method for setting selection to whole row from right context menu ?
Can you show it ?

To be honest I'm a bit surprised that you've managed to update state using the reference to ReactGrid, but anyways: if you want to select row then according to selectOneRow from selectRange.ts you'd need to update both the selectedIds and selectedIndexes. Could you try that?

When I was dealing with other problem I figured it out that it was problem with wrong value for document.activeElement after clicking on my new option from context menu.
Right now it is working correctly, I am updating the state with
spreadSheetRef.current.updateState(state => ({ ...state, selectionMode: "row", selectedIds: [pointetRowId], selectedIndexes: [rowIndex], }))
but after that the key thing was to set focus to .rg-hidden-element......