Skip to content

Commit

Permalink
Fix implementation on editing.changes accumulating
Browse files Browse the repository at this point in the history
Fixed an issue where the editing.changes array in the Grid was not cleared for newly-added rows that were subsequently deleted. This caused validation to fail as the deleted row's changes remained in the array, even though it was no longer displayed.
  • Loading branch information
PaulDevExpress committed Dec 26, 2024
1 parent cd4d587 commit 50109d7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ASP.NET Core/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<script>
function validateVisibleRows() {
const grid = $("#gridContainer").dxDataGrid("instance");
const currentChanges = grid.option("editing.changes");
const currentChanges = grid.option('editing.changes').filter(c => Object.keys(c.data).length > 0);
const fakeChanges = grid.getVisibleRows().map(function (row) {
return { type: "update", key: row.data.ID, data: {} };
});
Expand Down
4 changes: 3 additions & 1 deletion Angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ export class AppComponent implements AfterViewChecked {

validateVisibleRows(): void {
const dataGridInstance = this?.dataGrid?.instance;
const currentChanges = (dataGridInstance?.option('editing.changes') as DxDataGridTypes.DataChange[])
.filter((c) => Object.keys(c.data).length > 0);

Check failure on line 31 in Angular/src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / Angular

Expected indentation of 6 spaces but found 4
const fakeChanges = dataGridInstance
? dataGridInstance.getVisibleRows().map((row: DxDataGridTypes.Row): DxDataGridTypes.DataChange => ({ type: 'update', key: row.key, data: {} }))
: [];
this.changes = [...this.changes, ...fakeChanges];
this.changes = [...currentChanges, ...fakeChanges];
this.checked = true;
}

Expand Down
4 changes: 3 additions & 1 deletion React/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ function App(): JSX.Element {

const validateVisibleRows = React.useCallback(() => {
let dataGrid = grid?.current?.instance;
const currentChanges = (dataGrid?.option('editing.changes') as DataGridTypes.DataChange[])
.filter((c) => Object.keys(c.data).length > 0);

Check failure on line 21 in React/src/App.tsx

View workflow job for this annotation

GitHub Actions / React

Expected indentation of 6 spaces but found 4

Check failure on line 21 in React/src/App.tsx

View workflow job for this annotation

GitHub Actions / React

Expected indentation of 6 spaces but found 4
const fakeChanges = dataGrid
? dataGrid.getVisibleRows().map((row: DataGridTypes.Row): DataGridTypes.DataChange => ({ type: 'update', key: row.key, data: {} }))
: [];
// alternatively, you can use the DataGrid|option method to set a new changes array
setChanges([...changes, ...fakeChanges]);
setChanges([...currentChanges, ...fakeChanges]);
setClicked(true);
}, [changes]);

Expand Down
4 changes: 3 additions & 1 deletion Vue/src/components/HomeContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const dataGridRef = ref<DxDataGrid>();
const validateVisibleRows = () => {
const dataGridInstance = dataGridRef.value?.instance! as dxDataGrid;
const currentChanges = (dataGrid?.option('editing.changes') as DataGridTypes.DataChange[])

Check failure on line 70 in Vue/src/components/HomeContent.vue

View workflow job for this annotation

GitHub Actions / Vue

'dataGrid' is not defined

Check failure on line 70 in Vue/src/components/HomeContent.vue

View workflow job for this annotation

GitHub Actions / Vue

'DataGridTypes' is not defined
.filter((c) => Object.keys(c.data).length > 0);
const fakeChanges = dataGridInstance
? dataGridInstance
.getVisibleRows()
Expand All @@ -76,7 +78,7 @@ const validateVisibleRows = () => {
data: {}
}))
: [];
changes.value = [...changes.value, ...fakeChanges];
changes.value = [...currentChanges, ...fakeChanges];
clicked.value = true;
};
Expand Down
2 changes: 1 addition & 1 deletion jQuery/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $(() => {

function validateVisibleRows() {
const grid = $('#gridContainer').dxDataGrid('instance');
const currentChanges = grid.option('editing.changes');
const currentChanges = grid.option('editing.changes').filter(c => Object.keys(c.data).length > 0);

Check failure on line 46 in jQuery/src/index.js

View workflow job for this annotation

GitHub Actions / jQuery

Expected parentheses around arrow function argument
const fakeChanges = grid.getVisibleRows().map((row) => ({ type: 'update', key: row.key, data: {} }));

grid.option('editing.changes', [...currentChanges, ...fakeChanges]);
Expand Down

0 comments on commit 50109d7

Please sign in to comment.