Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column Resizer Double Click Listener #617

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

singharpit94
Copy link

@singharpit94 singharpit94 commented Jan 2, 2022

Description

Added support to pass a callback to listen to double click event of column resizer knob.
This can be very useful to enable excel like autofit columns in the table.

Motivation and Context

In Excel we have a very simple but cool ability to autofit the columns based on its contents, adding a listener for double click event on column resizer can help in implementing the same excel like autofit column feature in the table.

How Has This Been Tested?

Currently this has been tested locally in my system. Open to add test cases in any form wherever required.

Screenshots (if appropriate):

fdtos2

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

Added support to pass a callback to listen to double click
of column resizer knob. This can be very useful to enable excel like
autofit columns in the table.
@@ -436,6 +436,16 @@ class FixedDataTable extends React.Component {
* ```
*/
onColumnReorderEndCallback: PropTypes.func,
/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a new line to separate the prop types

Comment on lines 256 to +257
onMouseDown={this._onColumnResizerMouseDown}
onDoubleClick={this._onColumnResizerDoubleClick}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does onMouseDown work when the user double clicks the resizer? Is it going to be called twice? Do you see any issues that might pop up (eg: does the resize event trigger twice?)

Copy link
Author

@singharpit94 singharpit94 Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does onMouseDown work when the user double clicks the resizer? Is it going to be called twice? Do you see any issues that might pop up (eg: does the resize event trigger twice?)

Yes the resize does gets called twice, right now I have handled it to ignore the event if the new column width and current column width is same. Can we do something similar in fdt only. I also think this can potentially leave the column resize blue bar to not re render if we do not trigger mouse up?

The simplest way will be to leave upto the consumer to decide here similar to the way I am handling in my use case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably in this line, we can just do setState and do not call onResizeEnd if the props initialWidth and state width are equal?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see there is a need to re render FDT with prop isColumnResizing set as false because of this line

Copy link
Author

@singharpit94 singharpit94 Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay after taking a deeper look, I think we should introduce a COLUMN_RESIZE_END action type similar to COLUMN_RESIZE and call it on when column resize ends. This new action type can set isColumnResizing as false and also clear the columnResizing data in the state and at the same time decide to whether to call the user passed onColumnResizeEnd callback. This approach has two benefits, it takes away need to re render fdt to remove the column reisizer blue line and also will not call onColumnResizerEnd callback unnecessarily when the new and current column width are equal.

Let me know your thoughts on this

Copy link
Collaborator

@pradeepnschrodinger pradeepnschrodinger Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should introduce a COLUMN_RESIZE_END action type similar to COLUMN_RESIZE and call it on when column resize ends. This new action type can set isColumnResizing as false and also clear the columnResizing data in the state and at the same time decide to whether to call the user passed onColumnResizeEnd callback.

This sounds good to me. We should probably leave it up to the user to decide if they want to ignore the onColumnResizeEnd callback when the new and old widths are identical.

This new action type can set isColumnResizing as false and also clear the columnResizing data in the state

I got a question here: will there be any scenarios where the user doesn't want isColumnResizing to be false?
Maybe they want to ignore the current resize due to some reason, so in this case they'll plan to keep isColumnResizing as true.
Ideally we want the user to be able to control column resizing through the isColumnResizing prop but I'm not aware of any examples in the wild that set the prop dynamically. In both our application and in the resize example here, the prop is always set to false.

@@ -338,6 +340,10 @@ class FixedDataTableCell extends React.Component {
}
};

_onColumnResizerDoubleClick = () => {
this.props.onColumnResizerDoubleClick(this.props.columnKey);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is essentially a wrapper over the onDoubleClick event handler, it's a good idea to also pass the original html event to the user.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, will add it

@pradeepnschrodinger
Copy link
Collaborator

@singharpit94 , nice to see you again and thanks for the PR. This looks good.

It'd be neat if you could add a new example for this, maybe something like the auto resizer which you've shown in the screenshot.

Currently this has been tested locally in my system. Open to add test cases in any form wherever required.

It'd be a good idea to add a simple test case which ensures that double clicking on the resizer for a column actually triggers the double click handler for the said column.

Let me know if you need help with any of these.

@@ -121,6 +121,7 @@ class FixedDataTableRowImpl extends React.Component {
* @param object event
*/
onColumnResize: PropTypes.func,
onColumnResizerDoubleClick: PropTypes.func,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update the jsdoc for this prop as well?

@pradeepnschrodinger
Copy link
Collaborator

@singharpit94, hey any updates on this?

@pradeepnschrodinger
Copy link
Collaborator

@singharpit94 , friendly ping.

Let me know if there's anything to be done from our side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants