fin-hypergrid / core

A canvas-based super high performant grid renderer API
MIT License
898 stars 143 forks source link

selecting part of grid(multiple cell) and doing copy pasting #715

Closed vikrametc closed 6 years ago

vikrametc commented 6 years ago

Hi Team,

I have a requirement to copy part of the grid using arrow keys and paste the selected grid cell in xls, how can I do this?

I have attached the key-down event and able to trace user selection but how to get the value of those selected cells in Ctrl+C? Please help me

joneit commented 6 years ago

hello @vikrametc ...

Ctrl-C should work (Command-C on mac). Or are you saying you want to do the copy programmatically?

Jonathan

vikrametc commented 6 years ago

Hi Jonathan,

Basically I need to know what column user has selected and what is the ID for the row which user has selected and copied.

How can I do?

joneit commented 6 years ago
grid.selectionModel.selections[0].firstSelectedCell.x // left grid column index
grid.selectionModel.selections[0].firstSelectedCell.y // top data row index
grid.selectionModel.selections[0].lastSelectedCell.x // right grid column index
grid.selectionModel.selections[0].lastSelectedCell.y // bottom data row index
joneit commented 6 years ago

Following also works:

grid.selectionModel.selections[0].left // left grid column index
grid.selectionModel.selections[0].top // top data row index
grid.selectionModel.selections[0].right // right grid column index
grid.selectionModel.selections[0].bottom // bottom data row index
vikrametc commented 6 years ago

Thank you Jonathan, left, right, top, bottom worked.

Vikram

vikrametc commented 6 years ago

One more thing should I listen for key-down event for selection or is there any other event I can listen for the grid cells selection?

joneit commented 6 years ago

@vikrametc just saw your one more thing:

myGrid.addEventListenter('fin-selection-changed', function(event) {
    event.detail.selections[0].left // etc.
});
vikrametc commented 6 years ago

Hi Jonathan,

Thank you for your response, now since I got the left, right, top and bottom value, using this how can I get the cell value?

I am doing somehting like this this.grid.getGridCellFromMousePoint(event.detail.mouse).cellEvent; but this doesn't give me the actual cell.

Is there any other way?

joneit commented 6 years ago

please tell me the use case: what is the actual goal? i thought you were cutting & pasting to excel AND that you wanted to know the source coordinates.... just to be clear, cutting & pasting is already fully supported.

vikrametc commented 6 years ago

So I have a use case which is basically when user do a selection and doing copy pasting in other blotter(not excel), I need to get the data for those selection and show the updated blotter. To do this, I need to know the columns Name of the selection and the dataRow for the selection. Using left, right, top, bottom value how can I get the column header names and the respective dataRow?

Thank you

joneit commented 6 years ago

Copy (ctrl-C or command-C) puts the currently selected values in the copy buffer, tab-separated by column and newline-separated by row.

But even without user interaction (typing ctrl-C), the selected cells are available to you. For example, in the demo, I select a region:

region

In the console:

grid.getSelection()[0]

yields:

{
    last_name: ["Barbarosa", "Oneil", "DePena", "Gotti"],
    birthTime: [480, 620, 1316, 62]
}

or:

grid.getSelectionMatrix()[0]

yields:

[
    ["Barbarosa", "Oneil", "DePena", "Gotti"],
    [480, 620, 1316, 62]
]

Hope this helps. Jonathan

vikrametc commented 6 years ago

Thank you Jonathan, This is exactly what I wanted to know. Thanks for your help. Can you provide the documentation URL where I can see the info about using grid.

Thanks, Vikram

joneit commented 6 years ago

Hypergrid documentation is a work-in-progress. We definitely could use some help in this area! Hopefully after release of v3.0.0 I can put some time into it.

The documentation currently consists of:

The two methods do appear in the