We have configured generic numeric editing for columns in our grid.
We have successfully set the angular locale (for example, de) and are using the angular formatNumber method to display the correct value when not in edit mode.
However, we are using an igxInput for cell editing and cannot figure out how to have it display the correctly formatted value when editing starts.
Here is our cellEditor definition:
<ng-template igxCellEditor let-cell="cell" *ngIf="col.formatAsNumber"> <igx-input-group type="border"> <input igxInput type="text" [(ngModel)]="cell.editValue" [igxFocus]="true" (keypress)="numericEditorKeyPress($event)" /> </igx-input-group> </ng-template>
We use the kepypress event to resolve numeric editing issues in firefox and we use the type "text" because if we use number, the user cannot enter the correct numeric decimal separator (for example comma in German).
We do not require that the user's browser be in the specified language, only that the first language they have specified is used to control the formatting.
Here is the display value:
and here is the cell in edit mode
Here is the browser configuration (this is a common configuration for our international users since a lot of the work that they do is in English language, but they still need their dates and numbers displayed and editable in their native representation):
<ng-template igxCellEditor let-cell="cell"> <igx-input-group type="border"> <input igxInput type="text" [ngModel]="cell.editValue | germanLocale" (ngModelChange)="cell.editValue=$event" pattern="^-?\d{1,3}(?:\.\d{3})*(?:,\d+)?$" [igxFocus]="true" /> </igx-input-group> </ng-template>
@Pipe({ name: "germanLocale" }) export class GermanLocalePipe implements PipeTransform { transform(value: any): number { return value.toLocaleString("de-DE"); } }
public onCellEdit(event: IGridEditEventArgs) { if (event.column.field === "UnitPrice") { event.newValue = Number( event.newValue .toString() .replace(/\./g, "") .replace(/,/, ".") ); } }