Skip to content

Commit f67214a

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#29810)
1 parent a46cf7d commit f67214a

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

e2e/testcafe-devextreme/tests/dataGrid/common/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
@@ -928,11 +928,13 @@ class EditingControllerImpl extends modules.ViewController {
928928
case LAST_NEW_ROW_POSITION:
929929
break;
930930
case PAGE_TOP_NEW_ROW_POSITION:
931+
if (allItems.length) {
932+
change.insertBeforeKey = allItems[0].key;
933+
}
934+
break;
931935
case PAGE_BOTTOM_NEW_ROW_POSITION:
932936
if (allItems.length) {
933-
const itemIndex = newRowPosition === PAGE_TOP_NEW_ROW_POSITION ? 0 : allItems.length - 1;
934-
935-
change[itemIndex === 0 ? 'insertBeforeKey' : 'insertAfterKey'] = allItems[itemIndex].key;
937+
change.insertAfterKey = allItems[allItems.length - 1].key;
936938
}
937939
break;
938940
default: {

0 commit comments

Comments
 (0)