Hello,
We have a DataGrid control which has a ContextMenu with some options. The ContextMenu works fine on all desktop browsers on right click. The same works fine on mobile devices with tap and hold to show the ContextMenu, except for Safari on iPad.
From our understanding, Safari on iPadOS requests a desktop version of sites instead of a mobile version and as such, touch events from the Syncfusion library are not applicable. If we adjust the settings in Safari to get the Mobile version of our site, tap and hold ContextMenu works fine then.
This is replicable on your documentation page for the ASPNetCore DataGrid ContextMenu control - https://ej2.syncfusion.com/aspnetcore/Grid/ContextMenu
Can a property be provided on the DataGrid such that we could force the touch controls from the Application side?
Thanks,
Syed
|
var timer;
var touchduration = 500;
var touchEventArgs;
var contextMenuOpenFn;
// Grid’s created event handler
function onCreated() {
// Since the Grid element is the context menu’s target, the events are bound to the Grid element
grid.element.addEventListener('touchstart', touchstart.bind(this), false);
grid.element.addEventListener('touchend', touchend.bind(this), false);
// The Grid context menu’s beforeOpen event is stored in a global variable
contextMenuOpenFn = grid.contextMenuModule.contextMenu.beforeOpen;
// The Grid context menu’s beforeOpen event is overridden
grid.contextMenuModule.contextMenu.beforeOpen = function (e) {
// The Grid context menu’s beforeOpen event is overridden in order to pass the touch event arguments to is
// The event arguments stored from ‘onlongtouch’ event(can be checked below) is stored to the event property and the source method(stored in the global variable) is called
e.event = (e.event) ? e.event : touchEventArgs;
contextMenuOpenFn.call(this, e)
}
}
// Grid element’s ‘touchstart’ event handler
function touchstart(e) {
e.preventDefault();
if (!timer) {
timer = setTimeout(onlongtouch.bind(this, e), touchduration);
}
}
// Grid element’s ‘touchend’ event handler
function touchend(e) {
if (timer) {
clearTimeout(timer);
timer = null;
}
}
// Event will be triggered on long touch
function onlongtouch(e, e1) {
timer = null;
// The touch event arguments are stored in a global variable
touchEventArgs = e;
// the Grid’s context menu is opened with the target positions
grid.contextMenuModule.contextMenu.open(e.touches[0].pageY, e.touches[0].pageX);
}; |