Skip to content

Commit

Permalink
ROU-3950: Investigate the reason why the columns OnCellValueChange is…
Browse files Browse the repository at this point in the history
… not triggered with the original value (#306)

* Updated validation marks and dropdown validations

Updated validation marks and dropdown validations

* Update DropdownColumn.ts

* Update ValidationMark.ts

* ROU-3950: Added new validations to _cellEditBeforeEndingHandler

And updated _cellEditHandler to consider the cancel event.

* Fix eslint error

Co-authored-by: gbnm <[email protected]>
  • Loading branch information
OS-giulianasilva and gnbm committed Nov 25, 2022
1 parent 5c8f10f commit bbeff57
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/Providers/DataGrid/Wijmo/Columns/DropdownColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ namespace Providers.DataGrid.Wijmo.Column {
newValue: any
): void {
// only set to blank if there is a different value
if (oldValue !== newValue) {
if (
oldValue !== newValue &&
oldValue.toString() !== newValue.toString()
) {
const column = this.grid.getColumn(columnID);
const currentValue = this.grid.provider.getCellData(
rowNumber,
Expand Down
48 changes: 31 additions & 17 deletions src/Providers/DataGrid/Wijmo/Features/ValidationMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,30 @@ namespace Providers.DataGrid.Wijmo.Feature {

/**
* Handler for the CellEditEnding.
* It checks if the cell value effectively changed
* For this purpose, here we consider null == undefined == ''
* Bug: it does not work for checkboxes, since the activeEditor.value is always "on"
*/
private _cellEditBeforeEndingHandler(
s: wijmo.grid.FlexGrid,
e: wijmo.grid.CellRangeEventArgs
): void {
// get old and new values
const oldVal = s.getCellData(e.row, e.col, false) ?? '';
const newVal = s.activeEditor?.value ?? '';
// get the new value
const newValue = s.activeEditor?.value ?? '';
let currentValue = '';

// when a delete event occurs, s.getCellData() always returns an empty string
// because of that, we need to verify if a delete event occured and get the right current value
if (!!e.data && !!e.data.key && e.data.key === 'Delete') {
currentValue = e.data.target.textContent;
} else {
currentValue = s.getCellData(e.row, e.col, true) ?? '';
}

// cancel edits if oldVal is equals to newVal
e.cancel = oldVal === newVal;
// cancel edits if currentValue is equals to newValue
e.cancel =
currentValue === newValue ||
currentValue.toString() === newValue.toString();
}

/**
Expand All @@ -54,18 +67,19 @@ namespace Providers.DataGrid.Wijmo.Feature {
s: wijmo.grid.FlexGrid,
e: wijmo.grid.CellRangeEventArgs
): void {
const column = s.getColumn(e.col);
const OSColumn = this._grid
.getColumns()
.find((item) => item.provider.index === column.index);

const newValue = s.getCellData(e.row, e.col, false);
// The old value can be captured on the dirtyMark feature as it is the one responsible for saving the original values
const oldValue = this._grid.features.dirtyMark.getOldValue(
e.row,
column.binding
);
if (oldValue !== newValue) {
if (!e.cancel) {
const column = s.getColumn(e.col);
const OSColumn = this._grid
.getColumns()
.find((item) => item.provider.index === column.index);

const newValue = s.getCellData(e.row, e.col, false);
// The old value can be captured on the dirtyMark feature as it is the one responsible for saving the original values
const oldValue = this._grid.features.dirtyMark.getOldValue(
e.row,
column.binding
);

this._triggerEventsFromColumn(
e.row,
OSColumn.uniqueId,
Expand Down

0 comments on commit bbeff57

Please sign in to comment.