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

Adding row double click #59

Open
vlrmprjct opened this issue Nov 15, 2021 · 1 comment
Open

Adding row double click #59

vlrmprjct opened this issue Nov 15, 2021 · 1 comment
Assignees
Labels
feature A new feature to be added question Something is not clear

Comments

@vlrmprjct
Copy link

Hello,

Is there a way to implement a rowDoubleClick() Event ?
Sometimes it is better not to select a row with a single click, because every time a user (accidentally ) clicks in the table, the single click event is triggered.

@joaocarmo joaocarmo self-assigned this Nov 15, 2021
@joaocarmo joaocarmo added feature A new feature to be added question Something is not clear labels Nov 15, 2021
@joaocarmo
Copy link
Owner

Hi @vlrmprjct, thank you for your question!

For now, you can implement that using something like this:

import SmartDataTable from 'react-smart-data-table'

const handleOnDoubleRowClick = () => {
  let numOfClicks = 0

  return (e, data) => {
    numOfClicks++  

    // Reset the number of clicks after a short time
    setTimeout(() => {
      numOfClicks = 0
    }, 400)

    if (numOfClicks === 2) {
      numOfClicks = 0
      alert('Double click')
    }
  }
}

const handleOnRowClick = handleOnDoubleRowClick()

const App = () => (
  <main>
    <SmartDataTable name="test" data={data} onRowClick={handleOnRowClick} />
  </main>
)

Though I'll consider extending the API to make it simpler, since I can see the benefit of having it built-in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature to be added question Something is not clear
Projects
None yet
Development

No branches or pull requests

2 participants