react-smart-data-table
react-smart-data-table copied to clipboard
Adding row double click
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.
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.