Skip to content

Commit

Permalink
DataGrid - Fixes expandRow (T880769) (#12765)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickMitrokhin authored Apr 20, 2020
1 parent 1c3896b commit f5b2dca
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 9 deletions.
2 changes: 1 addition & 1 deletion js/ui/data_grid/ui.data_grid.editing.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ gridCore.registerModule('editing', extend(true, {}, editingModule, {
editingController && editingController.refresh();
}

this.callBase.apply(this, arguments);
return this.callBase.apply(this, arguments);
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions js/ui/data_grid/ui.data_grid.grouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,14 @@ const GroupingDataControllerExtender = (function() {
const that = this;
const dataSource = this._dataSource;

if(!dataSource) return;

const d = new Deferred();
when(dataSource.changeRowExpand(key)).done(function() {
that.load().done(d.resolve).fail(d.reject);
}).fail(d.reject);

if(!dataSource) {
d.resolve();
} else {
when(dataSource.changeRowExpand(key)).done(function() {
that.load().done(d.resolve).fail(d.reject);
}).fail(d.reject);
}
return d;
},
isRowExpanded: function(key) {
Expand Down
9 changes: 7 additions & 2 deletions js/ui/grid_core/ui.grid_core.master_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import gridCoreUtils from './ui.grid_core.utils';
import { grep } from '../../core/utils/common';
import { each } from '../../core/utils/iterator';
import { isDefined } from '../../core/utils/type';
import { when } from '../../core/utils/deferred';
import { when, Deferred } from '../../core/utils/deferred';

const MASTER_DETAIL_CELL_CLASS = 'dx-master-detail-cell';
const MASTER_DETAIL_ROW_CLASS = 'dx-master-detail-row';
Expand Down Expand Up @@ -110,8 +110,9 @@ module.exports = {
let expandIndex;
let editingController;

let result;
if(Array.isArray(key)) {
return that.callBase.apply(that, arguments);
result = that.callBase.apply(that, arguments);
} else {
expandIndex = gridCoreUtils.getIndexByKey(key, that._expandedItems);
if(expandIndex >= 0) {
Expand All @@ -131,7 +132,11 @@ module.exports = {
changeType: 'update',
rowIndices: that._getRowIndicesForExpand(key)
});

result = new Deferred().resolve();
}

return result;
},
_processDataItem: function(data, options) {
const that = this;
Expand Down
84 changes: 84 additions & 0 deletions testing/tests/DevExpress.ui.widgets.dataGrid/dataGrid.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18141,6 +18141,90 @@ QUnit.module('API methods', baseModuleConfig, () => {
assert.strictEqual(columns[1].width, 200, 'width of the second column');
assert.strictEqual(columns[2].width, 200, 'width of the third column');
});

QUnit.test('Group Row - expandRow should resolve its promise only after re-rendering (T880769)', function(assert) {
// arrange
const getRowsInfo = function(element) {
const $rows = $(element).find('.dx-datagrid-rowsview .dx-row[role=\'row\']');
return {
rowCount: $rows.length,
groupRow: $($rows.eq(0)).hasClass('dx-group-row'),
dataRow: $($rows.eq(1)).hasClass('dx-data-row')
};
};
const dataGrid = createDataGrid({
dataSource: [
{ column1: 'value1', column2: 'value2' }
],
grouping: {
autoExpandAll: false,
},
columns: [
{
dataField: 'column1',
groupIndex: 0
},
'column2'
],
onRowExpanded: function() {
const info = getRowsInfo(dataGrid.element());
assert.step(`rowExpanded rowCount: ${info.rowCount}, groupRow: ${info.groupRow}, dataRow: ${info.dataRow}`);
}
});
this.clock.tick();

// act
dataGrid.expandRow(['value1']).done(() => {
const info = getRowsInfo(dataGrid.element());

assert.step(`done rowCount: ${info.rowCount}, groupRow: ${info.groupRow}, dataRow: ${info.dataRow}`);
});
this.clock.tick();

assert.verifySteps([
'rowExpanded rowCount: 2, groupRow: true, dataRow: true',
'done rowCount: 2, groupRow: true, dataRow: true'
]);
});

QUnit.test('Master Row - expandRow should resolve its promise only after re-rendering (T880769)', function(assert) {
// arrange
const getRowsInfo = function(element) {
const $rows = $(element).find('.dx-datagrid-rowsview .dx-row[role=\'row\']');
return {
rowCount: $rows.length,
masterRow: $($rows.eq(0)).hasClass('dx-data-row'),
detailRow: $($rows.eq(1)).hasClass('dx-master-detail-row')
};
};
const dataGrid = createDataGrid({
keyExpr: 'id',
dataSource: [
{ id: 1 }
],
masterDetail: {
enabled: true
},
onRowExpanded: function() {
const info = getRowsInfo(dataGrid.element());
assert.step(`rowExpanded rowCount: ${info.rowCount}, masterRow: ${info.masterRow}, detailRow: ${info.detailRow}`);
}
});
this.clock.tick();

// act
dataGrid.expandRow(1).done(() => {
const info = getRowsInfo(dataGrid.element());

assert.step(`done rowCount: ${info.rowCount}, masterRow: ${info.masterRow}, detailRow: ${info.detailRow}`);
});
this.clock.tick();

assert.verifySteps([
'rowExpanded rowCount: 2, masterRow: true, detailRow: true',
'done rowCount: 2, masterRow: true, detailRow: true'
]);
});
});

QUnit.module('templates', baseModuleConfig, () => {
Expand Down

0 comments on commit f5b2dca

Please sign in to comment.