react-data-grid icon indicating copy to clipboard operation
react-data-grid copied to clipboard

Enable Cell Editing, and Disable Cell Drag

Open lord-xeon opened this issue 9 years ago • 16 comments

HAVE YOU ALREADY SEARCHED FOR SIMILAR ISSUES? PLEASE HELP US OUT AND DOUBLE-CHECK FIRST!

ALSO, PLEASE DON'T BE THAT PERSON WHO DELETES THIS TEMPLATE. IT'S HERE FOR A REASON.

THANKS!

WHICH VERSION OF REACT ARE YOU USING?

Officially Supported:
[ ] v0.14.x
Community Supported:
[x] v15.0.x

WHICH BROWSER ARE YOU USING?

Officially Supported:
[ ] IE 9 / IE 10 / IE 11
[ ] Edge
[x] Chrome
Should work:
[ ] Firefox
[ ] Safari

I'm submitting a ... (check one with "x")

[ ] bug report
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/adazzle/react-data-grid/blob/master/CONTRIBUTING.md

Current behavior When you pass in enableCellSelect={true} and a onGridRowsUpdated={props.onRowUpdate}, you can enter editing mode for cells. By default this enables the click and drag up/down to copy the given value into the selected cells (provided your onGridRowsUpdated function does that.

Expected/desired behavior

Reproduction of the problem If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem.

What is the expected behavior? I would like a way to still enable cell editing and selection, but disallow the click and drag functionality.

What is the motivation / use case for changing the behavior? Users are not expected/allowed to change that many rows with the same data in the project I'm working on.

Perhaps there is a property that does this already, but I can't seem to find it in the (little) documentation that exists.

lord-xeon avatar Jun 07 '17 14:06 lord-xeon

Agreed, it looks like in the code if the cell is editable, it adds the drag properties without a way to turn it off, specifically https://github.com/adazzle/react-data-grid/blob/master/packages/react-data-grid/src/Cell.js#L495 sets dragHandle if you can edit the cell and you set the enableCellSelect prop to true. Simply adding a !disableCellDrag to that check should get rid of it if you so desire by passing that prop disableCellDrag={true}

audiolion avatar Jun 09 '17 04:06 audiolion

I was able to fake it by hiding the drag-handle via CSS. But I think a programatic way on the grid itself would be best.

.drag-handle { display: none; }

lord-xeon avatar Jun 15 '17 14:06 lord-xeon

I would like to see a way to disable the onDoubleClick={this.onDragHandleDoubleClick} somehow. I like the drag, but I don't like how double clicking can overwrite all cells below that one.

dbraynard avatar Jun 20 '17 13:06 dbraynard

@dbraynard this package specifically tries to emulate an excel spreadsheet, where that is the default functionality and can't be disabled, but there might not be easy undo options so I can understand the desire for this

audiolion avatar Jun 20 '17 14:06 audiolion

I understand, though it is my #1 problem with Excel, at the same time. I really disagree with the concept. I look at it this way. You are already double clicking into the cell and if you happen to be a few mm off, you mistakenly perform worse than the opposite of your intentions.

dbraynard avatar Jun 20 '17 14:06 dbraynard

yeah, luckily with excel you are a ctrl/cmd + z away from an undo of the op, but with a web interface, you might have just sent multiple PUT requests that, maybe while undoable, certainly causes a lot of churn, unless you carefully design the interactions

audiolion avatar Jun 21 '17 10:06 audiolion

I would love to have both features available and not as must have.

yairniz avatar Jun 21 '17 11:06 yairniz

@audiolion,

you might have just sent multiple PUT requests

So, I'm trying to use Redux-form to let the user submit the data, so changes to the grid are not written immediately back until the user "Submits". However, it would be a great thing to turn off, nonetheless.

dbraynard avatar Jun 21 '17 16:06 dbraynard

@lord-xeon

I was able to fake it by hiding the drag-handle via CSS. But I think a programatic way on the grid itself would be best.

.drag-handle { display: none; }

I also do an extra check in handleGridRowsUpdated to ensure the row being updated is the same row as fromRow:

handleGridRowsUpdated({ fromRow, toRow, updated }) {
  if (fromRow !== toRow)
    return;

wiiiimm avatar Jul 10 '17 12:07 wiiiimm

+1 for programmatic way to turn off drag handle

shtabnoy avatar Jan 11 '18 12:01 shtabnoy

Yep, this. It's important to my application's design that you can only edit one cell at a time. Resorting to CSS makes me sad.

jstray avatar Feb 13 '18 23:02 jstray

When using the css hack to fix, I am still able if I position my mouse perfectly to activate the drag handle even when it's display:none. This caused a major issue with data in our app that was supposed to be uneditable.

The programmatic fix by checking fromRow and toRow has resolved this, but turning off the drag handle should really be a feature of this grid.

FrancisEgan avatar Jun 01 '18 19:06 FrancisEgan

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please reopen this if you feel it has been incorrectly closed and we will do our best to look into it. Thank you for your contributions.

stale[bot] avatar Jul 12 '18 10:07 stale[bot]

any updates?

vellov avatar Aug 01 '18 09:08 vellov

Hello. I run into this thread when looking for a way to override double click behaviour.

It appears, that handleGridRowsUpdated accepts an event object as parameter. Then, using inline destructuring, the examples give out the way to use the object items directly.

The event object contains an action item, for which value is CELL_UPDATE for singular update, CELL_DRAG for dragging and COLUMN_FILL for double click...

So, if, for example, you want to override double-click:

handleGridRowsUpdated = (e) => {
    const { action, cellKey, rowIds, fromRow, toRow, updated } = e
    if ( action === 'COLUMN_FILL' ) {
        return console.log('no action');
    }

    // do what you would normally do
}

This way, dragging works, double clicking does nothing. You can also add a confirmation dialog or any other logic (for example, update the full set and not only the current view, etc). Or you can override dragging and allow double clicking. Or you can override each one differently etcetera.

stasou avatar Sep 18 '18 06:09 stasou

I was able to fake it by hiding the drag-handle via CSS. But I think a programatic way on the grid itself would be best.

.drag-handle { display: none; }

Thanks, this works great for now!

ogg130 avatar Jan 19 '20 15:01 ogg130