Prevent Undo/Redo on FlexSheet

Posted by: holly.anderson on 26 October 2017, 2:11 am EST

    • Post Options:
    • Link

    Posted 26 October 2017, 2:11 am EST

    Hi,

    Is there any way to prevent users from using the undo/redo functionality on a FlexSheet? I don’t want the undo/redo actions to be performed when users type the corresponding keyboard shortcuts.

    Thanks,

    Holly

  • Posted 26 October 2017, 10:51 pm EST

    Hi Holly,

    You need to handle keyDown event and prevent action to be performed for Ctrl+z/y.

    ~Manish

  • Posted 30 October 2017, 1:01 am EST

    Hi Manish,

    Would this let me prevent undo/redo on the FlexSheet but allow those actions when they pertain to other elements on the page? If so, could you provide a little more detail on how to do that?

    Thanks,

    Holly

  • Posted 30 October 2017, 5:57 pm EST

    Hi Holly,

    Yes, you can limit this to FlexSheet only by handling keyDown event for FlexSheet hostElement. Please refer to the following code snippet for the same:

    flexSheet.hostElement.addEventListener("keydown",function(e){
    	// code to prevent undo/redo 
    
    });
    
  • Posted 2 November 2017, 2:42 am EST

    Hi Manish,

    I’m still having trouble with this. I’ve done the following, but the undo/redo actions are still being performed.

                
    flexSheet.hostElement.addEventListener("keydown", function (e) {
    	if (e.ctrlKey && (e.key === 'z' || e.key === 'y')) {
    		e.preventDefault();
    		e.stopPropagation();
    		return 
    	}
    });
    
    

    Holly

  • Posted 2 November 2017, 5:58 pm EST

    Sorry Holly,

    We need to capture the keyDown event for this. Please refer to the updated code snippet:

    flex.hostElement.addEventListener("keydown", function (e) {
                    if (e.ctrlKey && (e.key === 'z' || e.key === 'y')) {
                        e.preventDefault();
                        e.stopPropagation();
                    }
                },true);
    

    ~Manish

  • Posted 2 November 2017, 10:48 pm EST

    Hi Manish,

    This still isn’t working for me. Please see the attached sample and follow these steps:

    1. Single-click on the first Name cell and change the value to ‘Item0’.
    2. Use the down arrow key to move to the next row.
    3. Undo the last change via Ctrl+z.

    Results: The value in the first Name cell reverts to ‘Item1’.

    I think this might be a problem with version 5.20172.359. If I use 5.20172.334, then the undo/redo is prevented as expected.

    Holly

    FlexSheetDemo_KeyDown.zip

  • Posted 5 November 2017, 8:23 pm EST

    Hi Holly,

    We are sorry for the inconvenience. We are able to replicate the issue at our end with 5.20172.359 build and it seems a bug. Hence, this issue has been forwarded to the concerned team for further investigation with tracking id 295414.

    We will let you know as we get an update in on this.

    ~Manish

  • Posted 5 November 2017, 10:34 pm EST

    Hi Holly,

    Please use the following workaround in the meantime while this is getting fixed by development team:

    sheet.addEventListener(document.body,"keydown", function (e) {                
                    if (e.ctrlKey && (e.key === 'z' || e.key === 'y') && wijmo.contains(sheet.hostElement, e.target) ) {
                        e.preventDefault();
                        e.stopPropagation();
                    }
                },true);
    

    ~Manish

  • Posted 15 December 2017, 12:06 am EST

    Any update on when this will be fixed?

  • Posted 17 December 2017, 10:30 pm EST

    Hi Holly,

    This issue logged as enhancement and it will be included in the future releases but we can not provide any estimation.

    Hence, please use the provided workaround and let me know if you any query on this.

    ~Manish

  • Posted 27 February 2018, 11:22 pm EST

    Hi manish,

    I am using wijmo 5 with angular 2.I have same query. Preventdefault or stoppropagation is not working in flexsheet.

    I used your code:

    sheet.addEventListener(document.body,“keydown”, function (e) {

    if (e.ctrlKey && (e.key === ‘z’ || e.key === ‘y’) && wijmo.contains(sheet.hostElement, e.target) ) {

    e.preventDefault();

    e.stopPropagation();

    }

    },true);

    but these two functions are not preventing my function.Is there any solution

    Actually i want to stop delete event when I click on delete key.I am getting the event when delete key is pressed,but the two functions are not stopping it from deleting the data.

    With regards

    Dharna Bakshi

  • Posted 1 March 2018, 1:47 am EST

    We are sorry Dharna. At this time we do not have a solution for the same. I will however enquire with the Dev Team and let you know if we have any other possible workarounds.

  • Posted 1 March 2018, 2:16 am EST

    Hi Dharna,

    Please try following code:

    sheet.hostElement.addEventListener("keydown", function (e) {
    console.log(e.keyCode)
    if (e.ctrlKey) {
    if (e.keyCode === 90 || e.keyCode === 89) { // Z/Y
    e.preventDefault();
    e.stopImmediatePropagation();
    }
    }
    }, true);
    

    This should work fine.

    Note that you have to call stopImmediatePropagation. Calling preventDefault should be enough, but the sheet code does not check for defaultPrevented, so you really have to stop the event immediately like this.

    ~Manish

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels