Articles in this section

How to enter only numeric values in a JavaScript Spreadsheet?

This article explains how to enter only numeric values in a JavaScript Spreadsheet.

Check whether the entered value is a number on the cellSave event, and allow the value to be updated in the cell. If the entered data is not a number, use the updateCell method to restrict the data from being updated and clear the entered value.

[HTML]

   <div id="spreadsheet"></div>

[TS]

import { Spreadsheet } from '@syncfusion/ej2-spreadsheet'

let spreadsheet: Spreadsheet = new Spreadsheet({
   cellSave: function (args: {value: string, requestType: string, address: string}) {
       let numericValue : number = parseInt(args.value);
     // Check whether the entered value contains any characters
       if (Number.isNaN(numericValue)) {
           // Clear the entered value.
           spreadsheet.updateCell({ value: '' }, args.address); 
           alert('Only numbers are allowed..!');
       }
   }
});

spreadsheet.appendTo('#spreadsheet');

Sample Link:

Refer to the working sample for additional details and implementation: Sample

Output:

Only_numeric_value.gif

Looking for the full JavaScript Spreadsheet Editor component overview, features, pricing, and documentation? Visit the JavaScript Spreadsheet Editor page.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied