Here is the solution I developed:
let movement = {};
let boundary = {};
let scrollingActive = false;
let mainContainer = document.getElementById("main-container");
$('#data-table')
.on('dragstart', dragHandler, function(event, ui) {
boundary = {
right: $(mainContainer).offset().left + $(mainContainer).width() - 50,
left: $(mainContainer).offset().left + 50,
top: $(mainContainer).offset().top + 50,
bottom: $(mainContainer).offset().top + $(mainContainer).height() - 50
};
})
.on('dragstop', dragHandler, function(event, ui) {
movement = {};
})
.on('drag', dragHandler, function(event, ui) {
movement.right = event.clientX - boundary.right;
movement.left = boundary.left - event.clientX;
movement.up = boundary.top - event.clientY;
movement.down = event.clientY - boundary.bottom;
if ((movement.right > 0 || movement.left > 0|| movement.up > 0 || movement.down > 0) && !scrollingActive) {
initiateScroll();
scrollingActive = true;
} else {
scrollingActive = false;
}
});
function initiateScroll() {
if (movement.right > 0) {
mainContainer.scrollLeft = mainContainer.scrollLeft + (movement.right >> 1);
}
if (movement.left > 0) {
mainContainer.scrollLeft = mainContainer.scrollLeft - (movement.left >> 1);
}
if (movement.down > 0) {
mainContainer.scrollTop = mainContainer.scrollTop + (movement.down >> 1);
}
if (movement.up > 0) {
mainContainer.scrollTop = mainContainer.scrollTop - (movement.up >> 1);
}
if (movement.right > 0 || movement.left > 0 || movement.up > 0 || movement.down > 0) {
setTimeout(initiateScroll, 100);
}
}