Hello,
I am using Igx-data Grid. I have column for combination of string and number datatype.
I want to write few validations for the number column mentioned below:
1. restrict the column to max 99999.
2. Column should only allow numbers(no alphabets) . It is allowing e now.
3. No ',' should be allowed.
Hope to hear reply soon.
Thanks.
Update: i was able to do for 1,2 but how can i remove ',' in the column of datatype number ex: 10,124
Hello Shobhana,
I believe you can remove commas(',') from numeric cells using IgxColumnComponent's formatter function as illustrated in the thread below.https://ko.infragistics.com/community/forums/f/ignite-ui-for-angular/121349/how-many-decimal-places-can-i-show-for-data-type-number-in-igx-data-grid-angular
The return value of the formatter function will be the data that will appear in a cell.Can you please try the above to see if it meets your requirement?
can i get a reply please! Code snippet to remove commas (',' ) from numeric cells
You should be able to use the same formatter from the mentioned thread to remove commas.
----------------------onColumnInit(column: IgxColumnComponent) { if(column.field =="UnitPrice") { column.formatter = (unitPrice => { return unitPrice; }); }}----------------------
https://stackblitz.com/edit/angular-grid-decimal-places-mnxftz
i used the same formatter, but not able to remove commas from the column. Can u share the code snippet what logic removes commas from the igx column for number data type.
Thanks
Can you please try the following?
------------onColumnInit(column: IgxColumnComponent) { if(column.field =="your_field_key") { column.formatter = (a => { return a.toString().replace(/\,/g,''); }); }}------------
If the above does not work, can you possibly send a sample that reproduces your problem?
No, you cannot restrict data entry using formatter function.
I suggest you use onCellEdit event to perform data validation. For more details about how to implement validation on the edit event, please take a look at the document below.
https://ko.infragistics.com//angularsite/components/grid/editing.html#cell-validation-on-edit-event
One more thing can i achieve 1,2 of my question using column formatter. If yes, can you provide snippet please
Thank you so much Mihoko!! It worked :)