Remove the default behavior of keyboard

Posted by: priya_mehta on 27 August 2018, 12:06 am EST

    • Post Options:
    • Link

    Posted 27 August 2018, 12:06 am EST

    If i select the the Ctrl+A and Press Delete Key from the Keyboard

    It should be delete the all rows

    how can i prevent?

  • Posted 27 August 2018, 9:23 pm EST

    Hi,

    If we understand correctly you would like to stop the grid from deleting all the rows at once.

    To achieve this you need to handle the mousedown event and call preventDefault() if keyPressed is del key and all of the grid rows are selected.

    Please refer to the following code snippet:-

    grid.hostElement.addEventListener('keydown',(e)=>{
          	if(e.keyCode != wijmo.Key.Delete){
            	return;
            }        
            //key pressed is delete check if all rows are not selected
            let sel = grid.selection;
            let fullRange = new wijmo.grid.CellRange(0, 0, grid.rows.length-1, grid.columns.length-1);
            if(sel.contains(fullRange) && grid.rows.length>1){
            	e.preventDefault();
            }
          },true);
    

    You may also refer to the following fiddle for complete implementation:- https://jsfiddle.net/pt94gLnc/1/

    If you had a different requirement then please feel free to explain more about it.

    ~Sharad

Need extra support?

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

Learn More

Forum Channels