Skip to content

Infragistics Community Forum / Web / Ignite UI for Angular / Restrict the user to enter upto 9 digits for a particular number datatype column

Restrict the user to enter upto 9 digits for a particular number datatype column

New Discussion
Shobhana Suara
Shobhana Suara asked on May 7, 2020 8:54 AM

Hello,

I am using Igx-data Grid. I have column for combination of string and number datatype.

I want to write a validations for the number datatype column:

Requirement: Restrict the user to input only 9 digits for a particular column.

Hope to hear reply soon.

Thanks

Sign In to post a reply

Replies

  • 0
    Yuki Mita
    Yuki Mita answered on Apr 23, 2020 4:02 AM

    Hello Shobhana,

    You can limit the number of digits to 9 on the grid. The below example uses cell editor template, and handles two events to achieve your goal.

    1. Add a cell editor template, handle keydown and input event.

    2. On keydown event, allow end users to type while the typed value does not exceed 9 digits.

    3. On input event, if the pasted value exceeds 9 digits, truncate the exceeding part.

    
    	...
    	
    		
    			
    				
    			
    		
    	
    	...
    

    // Allow end users to type up to 9 digits
    onKeydown(evt: KeyboardEvent, editValue: number) {
      if (isNaN(+evt.key)) {
        return;
      }
      const digit = editValue.toString().length;
      if (digit < 9) {
        return;
      }
      return false;
    }
    
    // Truncate cell value if pasting exceeds 9 digits
    onInput(cell: IgxGridCellComponent) {
      cell.editValue = cell.editValue.toString().slice(0, 9);
    }

    You can see how it works on "Units in Stock" column of the sample.
    https://stackblitz.com/edit/angular-gsnjjk

    If you have any question with this, please let me know.

    Thank you,
    Yuki

    • 0
      Shobhana Suara
      Shobhana Suara answered on May 6, 2020 1:45 PM

      Thank you So Much Yuki 🙂 Much appreciate your help.

  • 0
    Shobhana Suara
    Shobhana Suara answered on May 6, 2020 1:55 PM

    One more thing Yuki. Is there a way to restore the grid with original values. Eg: when i edit the cell and than cancel the edit the new value is replaced with original value. Please let me know.

    • 0
      Yuki Mita
      Yuki Mita answered on May 7, 2020 8:54 AM

      Shobhana,

      I am glad that you have solved your initial question. For the second question, would you tell me the steps on how you cancel editing? On my side, once editing is cancelled by hitting ESC key, the original value is presented on the cell.

      Thank you,
      Yuki

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Shobhana Suara
Favorites
0
Replies
4
Created On
May 07, 2020
Last Post
5 years, 9 months ago

Suggested Discussions

Created by

Created on

May 7, 2020 8:54 AM

Last activity on

Feb 12, 2026 9:15 AM