Skip to content

Commit 20f11ca

Browse files
authored
DataGrid - A new row is added above the existing row if the data source is empty or contains only one record and newRowPosition is set to "pageBottom" (T1287287) (DevExpress#29811)
1 parent ad3d3f0 commit 20f11ca

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

e2e/testcafe-devextreme/tests/dataGrid/editing.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,3 +2736,34 @@ test('Focus behavior should be correct when editing cells', async (t) => {
27362736
mode: 'batch',
27372737
},
27382738
}));
2739+
2740+
test('DataGrid - A new row is added above the existing row if the data source is empty or contains only one record and newRowPosition is set to "pageBottom" (T1287287)', async (t) => {
2741+
const dataGrid = new DataGrid('#container');
2742+
const addRowButton = dataGrid.getHeaderPanel().getAddRowButton();
2743+
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
2744+
2745+
await t
2746+
.click(addRowButton)
2747+
.click(addRowButton);
2748+
2749+
await t
2750+
.expect(dataGrid.getDataRow(1).isInserted)
2751+
.ok()
2752+
.expect(await takeScreenshot('newRowPosition-pageBottom-add-row-to-bottom.png', dataGrid.element))
2753+
.ok()
2754+
.expect(compareResults.isValid())
2755+
.ok(compareResults.errorMessages());
2756+
}).before(async () => createWidget('dxDataGrid', {
2757+
dataSource: [],
2758+
keyExpr: 'ID',
2759+
editing: {
2760+
mode: 'batch',
2761+
allowAdding: true,
2762+
newRowPosition: 'pageBottom',
2763+
},
2764+
columns: [
2765+
{
2766+
dataField: 'A',
2767+
},
2768+
],
2769+
}));
2.62 KB
Loading

packages/devextreme/js/__internal/grids/grid_core/editing/m_editing.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,11 +929,13 @@ class EditingControllerImpl extends modules.ViewController {
929929
case LAST_NEW_ROW_POSITION:
930930
break;
931931
case PAGE_TOP_NEW_ROW_POSITION:
932+
if (allItems.length) {
933+
change.insertBeforeKey = allItems[0].key;
934+
}
935+
break;
932936
case PAGE_BOTTOM_NEW_ROW_POSITION:
933937
if (allItems.length) {
934-
const itemIndex = newRowPosition === PAGE_TOP_NEW_ROW_POSITION ? 0 : allItems.length - 1;
935-
936-
change[itemIndex === 0 ? 'insertBeforeKey' : 'insertAfterKey'] = allItems[itemIndex].key;
938+
change.insertAfterKey = allItems[allItems.length - 1].key;
937939
}
938940
break;
939941
default: {

0 commit comments

Comments
 (0)