Skip to content

Commit

Permalink
revise resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
tongsonbarbs committed Dec 5, 2024
1 parent f70c816 commit 5617c46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1536,19 +1536,6 @@ export class DataController extends DataHelperMixin(modules.Controller) {
}
}

public getLoadedKeyByRowIndex(rowIndex) {
const items = this.items();
while (rowIndex < items.length) {
const item = items[rowIndex];

if (item && !item.isNewRow) {
return item.key;
}
rowIndex++;
}
return undefined;
}

public getRowIndexByKey(key, byLoaded?) {
return gridCoreUtils.getIndexByKey(key, this.items(byLoaded));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ class EditingControllerImpl extends modules.ViewController {
visibleItemIndex++;
}

const insertKey = dataController.getLoadedKeyByRowIndex(visibleItemIndex);
const insertKey = dataController.getKeyByRowIndex(visibleItemIndex);

if (isDefined(insertKey)) {
change.insertBeforeKey = insertKey;
Expand Down Expand Up @@ -1699,6 +1699,23 @@ class EditingControllerImpl extends modules.ViewController {
}
} else if (this._processRemove(changes, editIndex, cancel)) {
hasSavedData = !cancel;
if (!cancel && change && change.type === DATA_EDIT_DATA_INSERT_TYPE) {
const tmpKey = results[i].key;

const savedRows = this._dataController.items().filter((item) => !item.isNewRow);
const topSavedRowKey = savedRows.length ? savedRows[0].key : null;

if (topSavedRowKey) {
changes.forEach((unsavedChange) => {
if (
unsavedChange.type === DATA_EDIT_DATA_INSERT_TYPE
&& unsavedChange.insertBeforeKey === tmpKey
) {
unsavedChange.insertBeforeKey = topSavedRowKey;
}
});
}
}
}
}

Expand Down

0 comments on commit 5617c46

Please sign in to comment.