Skip to content

Commit 522effb

Browse files
authored
T1325377 - PivotGrid: Field Panel - fix multiple operations (#33148)
1 parent 9a742dd commit 522effb

2 files changed

Lines changed: 57 additions & 14 deletions

File tree

packages/devextreme/js/__internal/grids/pivot_grid/m_widget.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,6 @@ class PivotGrid extends Widget {
402402
case 'allowSortingBySummary':
403403
case 'scrolling':
404404
case 'stateStoring':
405-
if (that._fieldChooserBase) {
406-
that._fieldChooserBase._dispose();
407-
}
408405
that._initDataController();
409406
that.getFieldChooserPopup().hide();
410407
that._renderFieldChooser();
@@ -1171,15 +1168,25 @@ class PivotGrid extends Widget {
11711168

11721169
that.$element().addClass(OVERFLOW_HIDDEN_CLASS);
11731170

1174-
that._fieldChooserBase = that._createComponent(that.$element(), FieldChooserBase, {
1171+
const fieldChooserBaseConfig = {
11751172
dataSource: that.getDataSource(),
11761173
encodeHtml: that.option('encodeHtml'),
11771174
allowFieldDragging: that.option('fieldPanel.allowFieldDragging'),
11781175
headerFilter: that.option('headerFilter'),
11791176
visible: that.option('visible'),
11801177
// @ts-expect-error ts-error
11811178
remoteSort: that.option('scrolling.mode') === 'virtual',
1182-
});
1179+
};
1180+
1181+
if (that._fieldChooserBase) {
1182+
that._fieldChooserBase.option(fieldChooserBaseConfig);
1183+
} else {
1184+
that._fieldChooserBase = that._createComponent(
1185+
that.$element(),
1186+
FieldChooserBase,
1187+
fieldChooserBaseConfig,
1188+
);
1189+
}
11831190

11841191
const dataArea = that._renderDataArea(dataAreaElement);
11851192
const rowsArea = that._renderRowsArea(rowsAreaElement);
@@ -1264,10 +1271,6 @@ class PivotGrid extends Widget {
12641271
const that = this;
12651272
clearTimeout(that._hideLoadingTimeoutID);
12661273

1267-
if (that._fieldChooserBase) {
1268-
that._fieldChooserBase._dispose();
1269-
}
1270-
12711274
if (that._dataController) {
12721275
that._dataController.dispose();
12731276
}

packages/devextreme/testing/tests/DevExpress.ui.widgets.pivotGrid/pivotGrid.tests.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,42 @@ QUnit.module('dxPivotGrid', {
908908
assert.equal($('.dx-header-filter-menu').find('.dx-list-item').text(), 'test <test>', 'encoded');
909909
});
910910

911+
QUnit.test('T1325377: Field panel operations should work after dataSource reassignment', function(assert) {
912+
const assignedDataSource = new PivotGridDataSource({
913+
fields: [
914+
{ dataField: 'region', area: 'row' },
915+
{ dataField: 'date', dataType: 'date', area: 'column' },
916+
{ dataField: 'sales', dataType: 'number', summaryType: 'sum', area: 'data' }
917+
],
918+
store: [
919+
{ region: 'North America', date: '2013/01/06', sales: 1740 },
920+
{ region: 'South America', date: '2013/01/13', sales: 850 }
921+
]
922+
});
923+
924+
const pivotGrid = createPivotGrid({
925+
allowSorting: true,
926+
allowFiltering: true,
927+
fieldPanel: {
928+
visible: true
929+
},
930+
dataSource: null
931+
});
932+
pivotGrid.option('dataSource', assignedDataSource);
933+
this.clock.tick(500);
934+
935+
const $pivotGrid = $('#pivotGrid');
936+
937+
$pivotGrid.find('.dx-area-description-cell .dx-area-field').first().trigger('dxclick');
938+
this.clock.tick(500);
939+
940+
$pivotGrid.find('.dx-header-filter').first().trigger('dxclick');
941+
this.clock.tick(500);
942+
943+
assert.equal(pivotGrid.getDataSource().state().fields[0].sortOrder, 'desc', 'sorting changes current dataSource state');
944+
assert.ok($('.dx-header-filter-menu').find('.dx-list-item').length > 0, 'header filter has items');
945+
});
946+
911947
QUnit.test('Field chooser inherits encodeHtml option', function(assert) {
912948
const pivotGrid = createPivotGrid({
913949
dataSource: {
@@ -1044,7 +1080,7 @@ QUnit.module('dxPivotGrid', {
10441080

10451081
});
10461082

1047-
QUnit.test('T1317109: fieldChooser disposes on dataSource change', function(assert) {
1083+
QUnit.test('T1317109: FieldChooserBase internal _dataSource matches PivotGrid on dataSource change', function(assert) {
10481084
const pivotGrid = createPivotGrid({
10491085
dataSource: {
10501086
rows: [],
@@ -1053,13 +1089,17 @@ QUnit.module('dxPivotGrid', {
10531089
}
10541090
});
10551091

1056-
const disposeSpy = sinon.spy(pivotGrid._fieldChooserBase, '_dispose');
1057-
10581092
pivotGrid.option('dataSource', this.testOptions.dataSource);
1059-
10601093
this.clock.tick(500);
10611094

1062-
assert.ok(disposeSpy.calledOnce, '_dispose was called once on dataSource change');
1095+
const fieldChooserBase = $('#pivotGrid').dxPivotGridFieldChooserBase('instance');
1096+
const pivotDataSource = pivotGrid.getDataSource();
1097+
1098+
assert.strictEqual(
1099+
fieldChooserBase._dataSource,
1100+
pivotDataSource,
1101+
'FieldChooserBase._dataSource must equal getDataSource() after dataSource change'
1102+
);
10631103
});
10641104

10651105
QUnit.test('not show field chooser popup on description area click when fieldChooser disabled', function(assert) {

0 commit comments

Comments
 (0)