react-smart-data-table icon indicating copy to clipboard operation
react-smart-data-table copied to clipboard

Adding row double click

Open vlrmprjct opened this issue 2 years ago • 1 comments

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.

vlrmprjct avatar Nov 15 '21 19:11 vlrmprjct

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.

joaocarmo avatar Nov 15 '21 22:11 joaocarmo