I have a dgrid table with a selection mode of toggle
. One of my requirements is to implement a double click on a row to trigger a function.
Here is what I have:
grid.on('.dgrid-content .dgrid-row:dblclick', function () {
window.alert('Hello world!');
});
The problem is that double-clicking also causes the selection events dgrid-select
and dgrid-deselect
to fire as it is also registering two single clicks to select.
I have tried adding this code but it does not work as intended:
var timer;
grid.on('.dgrid-content .dgrid-row:click', function (event) {
var row = this;
if (timer) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
clearTimeout(timer);
} else {
timer = window.setTimeout(function() {
// something to make the click go through?
row.emit('something here');
clearTimeout(timer);
}, 250);
}
});
Is there a way to achieve this?
I've consulted How to use both onclick and ondblclick on an element? but the answers there did not seem to work in my case.
I've also looked at the misc utilities and perhaps it is the debounce
function that I need but I am not sure how to use it.