reactgrid icon indicating copy to clipboard operation
reactgrid copied to clipboard

Is there a possibility to set selection ?

Open icyhot12 opened this issue 2 years ago • 6 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 avatar Jan 05 '24 13:01 icyhot12

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

qiufeihong2018 avatar Jan 08 '24 02:01 qiufeihong2018

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

icyhot12 avatar Jan 09 '24 10:01 icyhot12

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

Michota avatar Jan 10 '24 12:01 Michota

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 ?

icyhot12 avatar Jan 10 '24 12:01 icyhot12

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?

DLowHP avatar Jan 16 '24 09:01 DLowHP

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......

icyhot12 avatar Jan 23 '24 10:01 icyhot12