Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
8920
igGrid - restrict number of digits entered into 'number' cell
posted

here the code that creates columns array:

let gridColumns = [
{ key: 'idlr4ExhDetails', hidden: true, headerText: '', dataType: 'number', format: 'number', width: '0px', headerCssClass: '' },
{ key: 'idlr4ExhMrcSet', hidden: true, headerText: '', dataType: 'number', format: 'number', width: '0px', headerCssClass: '' },
{ key: 'idAccount', hidden: true, headerText: '', dataType: 'number', format: 'number', width: '0px', headerCssClass: '' },
{ key: 'acct_Desc', hidden: false, headerText: 'Accounts', dataType: 'string', width: '200px', headerCssClass: '' }
];
let fixedColumnSettings = [
{ columnKey: 'acct_Desc', isFixed: true, allowFixing: false }
];

for (let i: number = 0; i < this.pairColumns.length; i++) {
let pairColumn = this.pairColumns[i];
gridColumns.push({ key: pairColumn.key, hidden: false, headerText: pairColumn.headerText, dataType: 'number', format: 'number', width: '130px', headerCssClass: 'header-center-align' }); fixedColumnSettings.push({ columnKey: pairColumn.key, allowFixing: false, isFixed: pairColumn.fixed });
}
What & where can be added to restrict number of digits that can be entered into the grid's cell of data type 'number' to for example 15 ? means that only decimal (15.0) numbers are accepted. 
Thanks
  • 485
    Verified Answer
    Offline posted

    Hello Michael,

     

    Thank you for posting in our forum.

     

    The number of digits before the decimal separator could be validated by setting the “maxValue” editor option. For example if you need a maximum of 3 digits, it could be set to “maxValue: 999” – exceeding it would show a validation notification. The number of digits after the decimal separator could be set by enabling the “maxDecimals” option. Here is a sample snippet showing a maximum of 3 digits before the decimal separator and four after it:

     

    {
       name: "Updating",
       editMode: "cell",
       columnSettings: [
           {
               columnKey: "InStock",
               editorType: "numeric",
               editorOptions: {
                   maxDecimals: 4, // 4 digits after the decimal separator
                   maxValue: 999 // 3 digits before the decimal separator
               }
           }
       ]
    }
    

     

    Also, the igValidator has many options that allow the user to validate the input with more complex logic – like a custom validation function or regular expressions.

    If you need any additional assistance, feel free to contact me.