KeyPress Event for SpreadJs V 10.2.2

Posted by: tegbir.singh on 15 February 2018, 5:41 am EST

    • Post Options:
    • Link

    Posted 15 February 2018, 5:41 am EST

    Hi,

    We are using spreadjs (V 10.2.2) in our angular (typescript) application and need to apply few validations for the cell during keypress event. I didn’t find the keypress event in GC.Spread.Sheets.Events class.

    The following are the restrictions that need to be applied for the cell:

    1. Restrict the user from entering non-numeric characters for the specific cell.
    2. Value cannot be longer than 999 characters, characters after this are ignored.

    Please help.

    Regards,

    Tegbir

  • Posted 16 February 2018, 11:52 am EST

    Hello,

    You can set the Format for the cell to number format:

    http://help.grapecity.com/spread/SpreadSheets11/webframe.html#SpreadJS~GC.Spread.Sheets.CellRange~formatter.html

    Also you can handle the Keypress event for Spread div element using the code as follows:

    
     <div id="ss" onkeypress="myFunction(event)"></div>
        <script>
            var spread, sheet;
            window.onload = function () {
                 spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {});
                sheet = spread.getActiveSheet();
    		    sheet.getRange(3, 2, 4, 1).formatter('###');
            }
            function myFunction(event)
            {
         var theEvent = event || window.event;
            var key = theEvent.keyCode || theEvent.which;
      if ((key < 48 || key > 57) && !(key == 8 || key == 9 || key == 13 || key == 37 || key == 39 || key == 46) ){
        theEvent.returnValue = false;
        if (theEvent.preventDefault) theEvent.preventDefault();
      }
            }
        </script>
    
    

    You can get the length of edited value in edit end event and allow only 3 characters.

    I hope it helps.

    Thanks,

    Deepak Sharma

Need extra support?

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

Learn More

Forum Channels