Skip to content

Commit ab5b637

Browse files
authored
T1325377 - PivotGrid: Field Panel - fix multiple operations (#33096)
1 parent d39b960 commit ab5b637

File tree

2 files changed

+57
-14
lines changed

2 files changed

+57
-14
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,6 @@ class PivotGrid extends Widget {
410410
case 'allowSortingBySummary':
411411
case 'scrolling':
412412
case 'stateStoring':
413-
if (that._fieldChooserBase) {
414-
that._fieldChooserBase._dispose();
415-
}
416413
that._initDataController();
417414
that.getFieldChooserPopup().hide();
418415
that._renderFieldChooser();
@@ -1179,15 +1176,25 @@ class PivotGrid extends Widget {
11791176

11801177
that.$element().addClass(OVERFLOW_HIDDEN_CLASS);
11811178

1182-
that._fieldChooserBase = that._createComponent(that.$element(), FieldChooserBase, {
1179+
const fieldChooserBaseConfig = {
11831180
dataSource: that.getDataSource(),
11841181
encodeHtml: that.option('encodeHtml'),
11851182
allowFieldDragging: that.option('fieldPanel.allowFieldDragging'),
11861183
headerFilter: that.option('headerFilter'),
11871184
visible: that.option('visible'),
11881185
// @ts-expect-error ts-error
11891186
remoteSort: that.option('scrolling.mode') === 'virtual',
1190-
});
1187+
};
1188+
1189+
if (that._fieldChooserBase) {
1190+
that._fieldChooserBase.option(fieldChooserBaseConfig);
1191+
} else {
1192+
that._fieldChooserBase = that._createComponent(
1193+
that.$element(),
1194+
FieldChooserBase,
1195+
fieldChooserBaseConfig,
1196+
);
1197+
}
11911198

11921199
const dataArea = that._renderDataArea(dataAreaElement);
11931200
const rowsArea = that._renderRowsArea(rowsAreaElement);
@@ -1272,10 +1279,6 @@ class PivotGrid extends Widget {
12721279
const that = this;
12731280
clearTimeout(that._hideLoadingTimeoutID);
12741281

1275-
if (that._fieldChooserBase) {
1276-
that._fieldChooserBase._dispose();
1277-
}
1278-
12791282
if (that._dataController) {
12801283
that._dataController.dispose();
12811284
}

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
@@ -907,6 +907,42 @@ QUnit.module('dxPivotGrid', {
907907
assert.equal($('.dx-header-filter-menu').find('.dx-list-item').text(), 'test <test>', 'encoded');
908908
});
909909

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

10441080
});
10451081

1046-
QUnit.test('T1317109: fieldChooser disposes on dataSource change', function(assert) {
1082+
QUnit.test('T1317109: FieldChooserBase internal _dataSource matches PivotGrid on dataSource change', function(assert) {
10471083
const pivotGrid = createPivotGrid({
10481084
dataSource: {
10491085
rows: [],
@@ -1052,13 +1088,17 @@ QUnit.module('dxPivotGrid', {
10521088
}
10531089
});
10541090

1055-
const disposeSpy = sinon.spy(pivotGrid._fieldChooserBase, '_dispose');
1056-
10571091
pivotGrid.option('dataSource', this.testOptions.dataSource);
1058-
10591092
this.clock.tick(500);
10601093

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

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

0 commit comments

Comments
 (0)