Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ ModuleRegistry.registerModules([

let gridApi: GridApi;

const currencyFormatter = ({ value }: ValueFormatterParams) => `$ ${Number(value).toFixed(2)}`;
const valueFormatter = ({ value }: ValueFormatterParams) => `$ ${Number(value).toFixed(2)}`;

const gridOptions: GridOptions = {
columnDefs: [
{ field: 'item' },
{ field: 'price', valueFormatter: currencyFormatter },
{ field: 'price', valueFormatter },
{ field: 'qty' },
{ field: 'total', allowFormula: true, cellEditor: 'agTextCellEditor', valueFormatter: currencyFormatter },
{ field: 'total', allowFormula: true, cellEditor: 'agTextCellEditor', valueFormatter },
],
getRowId: (params: GetRowIdParams) => String(params.data.id),
defaultColDef: {
Expand Down
8 changes: 4 additions & 4 deletions packages/ag-grid-community/src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import type { DragService } from '../dragAndDrop/dragService';
import type { HorizontalResizeService } from '../dragAndDrop/horizontalResizeService';
import type { RowDragService } from '../dragAndDrop/rowDragService';
import type { RowDropHighlightService } from '../dragAndDrop/rowDropHighlightService';
import type { EditModelService } from '../edit/editModelService';
import type { EditService } from '../edit/editService';
import type { GridOptions } from '../entities/gridOptions';
import type { Environment } from '../environment';
import type { AgEventTypeParams, AgGlobalEventListener } from '../events';
Expand Down Expand Up @@ -56,8 +58,6 @@ import type { IColumnCollectionService } from '../interfaces/iColumnCollectionSe
import type { AgGridCommon } from '../interfaces/iCommon';
import type { IContextMenuService } from '../interfaces/iContextMenu';
import type { ICsvCreator } from '../interfaces/iCsvCreator';
import type { IEditModelService } from '../interfaces/iEditModelService';
import type { IEditService } from '../interfaces/iEditService';
import type { IExcelCreator } from '../interfaces/iExcelCreator';
import type { IExpansionService } from '../interfaces/iExpansionService';
import type { IFindService } from '../interfaces/iFind';
Expand Down Expand Up @@ -321,8 +321,8 @@ interface CoreBeanCollection
filterMenuFactory?: IMenuFactory;
enterpriseMenuFactory?: IMenuFactory;
contextMenuSvc?: IContextMenuService;
editSvc?: IEditService;
editModelSvc?: IEditModelService;
editSvc?: EditService;
editModelSvc?: EditModelService;
alignedGridsSvc?: AlignedGridsService;
paginationAutoPageSizeSvc?: PaginationAutoPageSizeService;
pagination?: PaginationService;
Expand Down
16 changes: 8 additions & 8 deletions packages/ag-grid-community/src/edit/editApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { BeanCollection } from '../context/context';
import type { EditingCellPosition } from '../interfaces/iCellEditor';
import type { CellPosition } from '../interfaces/iCellPosition';
import type { Column } from '../interfaces/iColumn';
import type { EditMap, EditRow, IEditModelService } from '../interfaces/iEditModelService';
import type { IEditService } from '../interfaces/iEditService';
import type { EditMap, EditRow } from '../interfaces/iEditModelService';
import type { IRowNode } from '../interfaces/iRowNode';
import type { CellCtrl } from '../rendering/cell/cellCtrl';
import type { RowCtrl } from '../rendering/row/rowCtrl';
import type { RowRenderer } from '../rendering/rowRenderer';
import type { ValueService } from '../valueService/valueService';
import { getEditingCells } from './editApi';
import type { EditModelService } from './editModelService';
import { EditService } from './editService';
import { SingleCellEditStrategy } from './strategy/singleCellEditStrategy';
import { UNEDITED } from './utils/editors';
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('Edit API', () => {
let editMap: EditMap | undefined;
let beans: BeanCollection;

let editSvc: IEditService;
let editSvc: EditService;
let setEditingCells: (beans: BeanCollection, cells: EditingCellPosition[], params?: { update?: boolean }) => void;

beforeEach(() => {
Expand All @@ -66,7 +66,7 @@ describe('Edit API', () => {
em.forEach((value, key) => editMap!.set(key, value));
}),
hasEdits: jest.fn(() => editMap && editMap.size > 0),
} as unknown as IEditModelService,
} as unknown as EditModelService,
colModel: {
getCol: jest.fn((col: Column | string) => {
const colId = typeof col === 'string' ? col : col.getColId();
Expand Down Expand Up @@ -130,11 +130,11 @@ describe('Edit API', () => {
beans.editSvc = editSvc;
editSvc['beans'] = beans;
editSvc['gos'] = beans.gos;
editSvc['model'] = beans.editModelSvc;
editSvc['model'] = beans.editModelSvc!;
editSvc['strategy'] = new SingleCellEditStrategy();
editSvc['strategy'].model = beans.editModelSvc;
editSvc['strategy'].editSvc = editSvc;
editSvc['strategy'].beans = beans;
editSvc['strategy']['model'] = beans.editModelSvc!;
editSvc['strategy']['editSvc'] = editSvc;
editSvc['strategy']['beans'] = beans;
editSvc['strategy'].start = jest.fn();

setEditingCells = (beans, cells: any[], params?: any) => editSvc.setEditingCells(cells, params);
Expand Down
25 changes: 11 additions & 14 deletions packages/ag-grid-community/src/edit/editModelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@ import type {
EditValidationMap,
EditValue,
GetEditsParams,
IEditCellValidationModel,
IEditModelService,
IEditRowValidationModel,
} from '../interfaces/iEditModelService';
import type { EditPosition, EditRowPosition } from '../interfaces/iEditService';
import type { IRowNode } from '../interfaces/iRowNode';
import { UNEDITED } from './utils/editors';

export class EditModelService extends BeanStub implements NamedBean, IEditModelService {
export class EditModelService extends BeanStub implements NamedBean {
public beanName = 'editModelSvc' as const;

private readonly edits: EditMap = new Map();
private cellValidations: IEditCellValidationModel = new EditCellValidationModel();
private rowValidations: IEditRowValidationModel = new EditRowValidationModel();
private cellValidations: EditCellValidationModel = new EditCellValidationModel();
private rowValidations: EditRowValidationModel = new EditRowValidationModel();

// during some operations, we want to always return false from `hasEdits`
private suspendEdits = false;
Expand Down Expand Up @@ -112,7 +109,7 @@ export class EditModelService extends BeanStub implements NamedBean, IEditModelS
return data;
}

public getEdit(position: EditPosition, params?: GetEditsParams): EditValue | undefined {
public getEdit(position: EditPosition = {}, params?: GetEditsParams): EditValue | undefined {
const { rowNode, column } = position;
const edits = this.edits;
if (this.suspendEdits || edits.size === 0 || !rowNode || !column) {
Expand Down Expand Up @@ -300,7 +297,7 @@ export class EditModelService extends BeanStub implements NamedBean, IEditModelS
map.set(column, {
editorValue: undefined,
pendingValue: UNEDITED,
sourceValue: this.beans.valueSvc.getValue(column as AgColumn, rowNode, false, 'api'),
sourceValue: this.beans.valueSvc.getValue(column as AgColumn, rowNode, 'data'),
state: 'editing',
editorState: {
isCancelAfterEnd: undefined,
Expand Down Expand Up @@ -330,19 +327,19 @@ export class EditModelService extends BeanStub implements NamedBean, IEditModelS
this.edits.clear();
}

public getCellValidationModel(): IEditCellValidationModel {
public getCellValidationModel(): EditCellValidationModel {
return this.cellValidations;
}

public getRowValidationModel(): IEditRowValidationModel {
public getRowValidationModel(): EditRowValidationModel {
return this.rowValidations;
}

public setCellValidationModel(model: IEditCellValidationModel): void {
public setCellValidationModel(model: EditCellValidationModel): void {
this.cellValidations = model;
}

public setRowValidationModel(model: IEditRowValidationModel): void {
public setRowValidationModel(model: EditRowValidationModel): void {
this.rowValidations = model;
}

Expand All @@ -352,7 +349,7 @@ export class EditModelService extends BeanStub implements NamedBean, IEditModelS
}
}

export class EditCellValidationModel implements IEditCellValidationModel {
export class EditCellValidationModel {
private cellValidations: EditValidationMap = new Map();

public getCellValidation(position?: EditPosition): EditValidation | undefined {
Expand Down Expand Up @@ -392,7 +389,7 @@ export class EditCellValidationModel implements IEditCellValidationModel {
this.cellValidations.clear();
}
}
export class EditRowValidationModel implements IEditRowValidationModel {
export class EditRowValidationModel {
private rowValidations: EditRowValidationMap = new Map();

public getRowValidation(position?: EditRowPosition): EditValidation | undefined {
Expand Down
57 changes: 35 additions & 22 deletions packages/ag-grid-community/src/edit/editService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import type { EditingCellPosition, ICellEditorParams, ICellEditorValidationError
import type { CellPosition } from '../interfaces/iCellPosition';
import type { RefreshCellsParams } from '../interfaces/iCellsParams';
import type { Column } from '../interfaces/iColumn';
import type { EditMap, EditRow, EditValue, IEditModelService } from '../interfaces/iEditModelService';
import type { EditMap, EditPositionValue, EditRow, EditValue } from '../interfaces/iEditModelService';
import type {
CellValueResolveFrom,
EditNavOnValidationResult,
EditPosition,
EditSource,
IEditService,
IsEditingParams,
StartEditParams,
StopEditParams,
Expand All @@ -33,6 +33,7 @@ import { CellCtrl } from '../rendering/cell/cellCtrl';
import type { RowCtrl } from '../rendering/row/rowCtrl';
import type { ValueService } from '../valueService/valueService';
import { PopupEditorWrapper } from './cellEditors/popupEditorWrapper';
import type { EditModelService } from './editModelService';
import type { BaseEditStrategy } from './strategy/baseEditStrategy';
import { isCellEditable, isFullRowCellEditable, shouldStartEditing } from './strategy/strategyUtils';
import { CellEditStyleFeature } from './styles/cellEditStyleFeature';
Expand Down Expand Up @@ -98,13 +99,13 @@ const CHECK_SIBLING = { checkSiblings: true };

const FORCE_REFRESH = { force: true, suppressFlash: true };

export class EditService extends BeanStub implements NamedBean, IEditService {
export class EditService extends BeanStub implements NamedBean {
public beanName = 'editSvc' as const;

public committing = false;

private batch: boolean = false;
private model: IEditModelService;
private model: EditModelService;
private valueSvc: ValueService;
private rangeSvc: IRangeService;
private strategy?: BaseEditStrategy;
Expand Down Expand Up @@ -229,8 +230,8 @@ export class EditService extends BeanStub implements NamedBean, IEditService {
return _validateEdit(this.beans);
}

public isEditing(position?: EditPosition, params?: IsEditingParams): boolean {
return this.model.hasEdits(position, params ?? CHECK_SIBLING);
public isEditing(position?: EditPosition | null, params?: IsEditingParams): boolean {
return this.model.hasEdits(position ?? undefined, params ?? CHECK_SIBLING);
}

public isRowEditing(rowNode?: IRowNode, params?: IsEditingParams): boolean {
Expand Down Expand Up @@ -865,30 +866,42 @@ export class EditService extends BeanStub implements NamedBean, IEditService {
return res;
}

/** Gets the pending edit value for display (used by ValueService). Returns undefined to fallback to valueGetter. */
public getCellValueForDisplay(rowNode: IRowNode, column: Column, source: 'ui' | 'api' | string): any {
if (source !== 'ui') {
return undefined; // only show edit values for UI operations
/**
* Gets the pending edit value for display (used by ValueService).
* Returns undefined to fallback to data/valueGetter.
*/
public getCellValueForDisplay(rowNode: IRowNode, column: Column, from: CellValueResolveFrom): any {
if (from === 'data') {
return undefined; // 'data' mode: always use committed data, never edit values
}

if (from === 'batch' && !this.batch) {
return undefined; // 'batch' mode: only return edit values when batch editing is active
}

const edit = this.model.getEdit({ rowNode, column }, CHECK_SIBLING);
if (!edit) {
return undefined;
}

// Skip if no edit, or during stopEditing when value was already committed (non-batch, no editor opened)
if (!edit || (this.stopping && !this.batch && !edit.editorState?.cellStartedEditing)) {
return undefined; // no edit or value already committed
// Skip during stopEditing when value was already committed (non-batch, no editor opened)
if (this.stopping && !this.batch && !edit.editorState?.cellStartedEditing) {
return undefined;
}

const editorValue = edit.editorValue;
if (editorValue != null && editorValue !== UNEDITED) {
return editorValue; // live value from editor component
if (from === 'edit') {
const editorValue = edit.editorValue;
if (editorValue != null && editorValue !== UNEDITED) {
return editorValue; // For 'edit' mode: return editorValue (live typing) if available
}
}

const pendingValue = edit.pendingValue;
if (pendingValue !== UNEDITED) {
return pendingValue; // synced pending value
return pendingValue; // Return batch pending value if available
}

return undefined; // fallback to valueGetter
return undefined;
}

public getCellDataValue(position: Required<EditPosition>): any {
Expand All @@ -905,7 +918,7 @@ export class EditService extends BeanStub implements NamedBean, IEditService {
}

// fallback to getting value from ValueService
return this.valueSvc.getValue(position.column as AgColumn, position.rowNode, false, 'api');
return this.valueSvc.getValue(position.column as AgColumn, position.rowNode, 'data');
}

public addStopEditingWhenGridLosesFocus(viewports: HTMLElement[]): void {
Expand Down Expand Up @@ -1063,7 +1076,7 @@ export class EditService extends BeanStub implements NamedBean, IEditService {
}

private toEventChangeList(edits: EditMap): CellValueChange[] {
return this.model.getEditPositions(edits).map((edit) => ({
return this.model.getEditPositions(edits).map((edit: EditPositionValue) => ({
rowIndex: edit.rowNode.rowIndex!,
rowPinned: edit.rowNode.rowPinned,
columnId: edit.column.getColId(),
Expand Down Expand Up @@ -1109,7 +1122,7 @@ export class EditService extends BeanStub implements NamedBean, IEditService {
const isFormulaForColumn = !!isFormula && column.isAllowFormula();

if (this.isCellEditable({ rowNode, column }, 'api')) {
const sourceValue = valueSvc.getValue(column as AgColumn, rowNode, true, 'api');
const sourceValue = valueSvc.getValue(column as AgColumn, rowNode, 'data', true);
let pendingValue = valueSvc.parseValue(
column as AgColumn,
rowNode ?? null,
Expand Down Expand Up @@ -1199,7 +1212,7 @@ export class EditService extends BeanStub implements NamedBean, IEditService {
if (!rowNode) {
continue;
}
const sourceValue = valueSvc.getValue(col as AgColumn, rowNode, true, 'api');
const sourceValue = valueSvc.getValue(col as AgColumn, rowNode, 'data', true);

if (
!params?.forceRefreshOfEditCellsOnly &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import type { AgColumn } from '../../entities/agColumn';
import { _getRowNode } from '../../entities/positionUtils';
import type { AgEventType } from '../../eventTypes';
import type { CellFocusClearedEvent, CellFocusedEvent, CommonCellFocusParams } from '../../events';
import type { EditMap, EditValue, IEditModelService } from '../../interfaces/iEditModelService';
import type { EditMap, EditValue } from '../../interfaces/iEditModelService';
import type {
EditInputEvents,
EditPosition,
EditRowPosition,
EditSource,
IEditService,
StartEditWithPositionParams,
_SetEditingCellsParams,
} from '../../interfaces/iEditService';
import type { CellCtrl } from '../../rendering/cell/cellCtrl';
import type { EditModelService } from '../editModelService';
import type { EditService } from '../editService';
import { _getCellCtrl, _getRowCtrl } from '../utils/controllers';
import {
UNEDITED,
Expand All @@ -39,8 +40,8 @@ export type EditValidationAction<T extends Required<EditPosition> = Required<Edi

export abstract class BaseEditStrategy extends BeanStub {
beanName: BeanName | undefined;
protected model: IEditModelService;
protected editSvc: IEditService;
protected model: EditModelService;
protected editSvc: EditService;

public postConstruct(): void {
this.model = this.beans.editModelSvc!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { BeanStub } from '../../context/beanStub';
import type { BeanCollection } from '../../context/context';
import type { ICellStyleFeature } from '../../interfaces/iCellStyleFeature';
import type { IEditModelService } from '../../interfaces/iEditModelService';
import type { IEditService } from '../../interfaces/iEditService';
import type { CellCtrl, ICellComp } from '../../rendering/cell/cellCtrl';
import type { EditModelService } from '../editModelService';
import type { EditService } from '../editService';
import { _hasEdits, _hasLeafEdits, _hasPinnedEdits } from './style-utils';

export class CellEditStyleFeature extends BeanStub implements ICellStyleFeature {
private cellComp: ICellComp;

private readonly editSvc?: IEditService;
private readonly editModelSvc?: IEditModelService;
private readonly editSvc?: EditService;
private readonly editModelSvc?: EditModelService;

constructor(
private readonly cellCtrl: CellCtrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { BeanStub } from '../../context/beanStub';
import type { BeanCollection } from '../../context/context';
import type { IEditModelService } from '../../interfaces/iEditModelService';
import type { IEditService } from '../../interfaces/iEditService';
import type { IRowStyleFeature } from '../../interfaces/iRowStyleFeature';
import type { RowCtrl } from '../../rendering/row/rowCtrl';
import type { EditModelService } from '../editModelService';
import type { EditService } from '../editService';
import { _hasEdits, _hasLeafEdits, _hasPinnedEdits } from './style-utils';

export class RowEditStyleFeature extends BeanStub implements IRowStyleFeature {
private readonly editSvc?: IEditService;
private readonly editModelSvc?: IEditModelService;
private readonly editSvc?: EditService;
private readonly editModelSvc?: EditModelService;

constructor(
private readonly rowCtrl: RowCtrl,
Expand Down
Loading
Loading