Commit 112d869e by Ooh-Ao

perspective

parent 57308f04
...@@ -371,11 +371,8 @@ export class DashboardManagementComponent implements OnInit { ...@@ -371,11 +371,8 @@ export class DashboardManagementComponent implements OnInit {
configObject = { ...widget.config }; // Create a shallow copy configObject = { ...widget.config }; // Create a shallow copy
} }
// Inject widgetId and perspective into the config for the component // Inject widgetId into the config for the component
configObject.widgetId = widget.widgetId; configObject.widgetId = widget.widgetId;
if (widget.perspective) {
configObject.perspective = widget.perspective;
}
return { return {
id: widget.widgetId, id: widget.widgetId,
...@@ -385,7 +382,10 @@ export class DashboardManagementComponent implements OnInit { ...@@ -385,7 +382,10 @@ export class DashboardManagementComponent implements OnInit {
row: widget.y, row: widget.y,
col: widget.x, col: widget.x,
componentType: this.widgetComponentMap[widget.component], componentType: this.widgetComponentMap[widget.component],
componentInputs: { config: configObject }, componentInputs: {
config: configObject,
perspective: widget.perspective
},
originalWidget: widget originalWidget: widget
}; };
}); });
......
...@@ -5,6 +5,7 @@ import { DashboardStateService, SelectedDataset } from '../services/dashboard-st ...@@ -5,6 +5,7 @@ import { DashboardStateService, SelectedDataset } from '../services/dashboard-st
@Directive() // Use @Directive() for base classes without their own template @Directive() // Use @Directive() for base classes without their own template
export abstract class BaseWidgetComponent implements OnInit, OnDestroy { export abstract class BaseWidgetComponent implements OnInit, OnDestroy {
@Input() config: any; @Input() config: any;
@Input() perspective: string | null = null;
public title: string; public title: string;
public isLoading = true; public isLoading = true;
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
[columnMenuItems]="columnMenuItems" [columnMenuItems]="columnMenuItems"
(columnMenuClick)="onColumnMenuClick($event)" (columnMenuClick)="onColumnMenuClick($event)"
(actionComplete)="actionComplete($event)" (actionComplete)="actionComplete($event)"
(dataBound)="onDataBound($event)"
height="100%"> height="100%">
<e-columns> <e-columns>
<e-column *ngFor="let col of columns" [field]="col.field" [headerText]="col.headerText" [width]="col.width" <e-column *ngFor="let col of columns" [field]="col.field" [headerText]="col.headerText" [width]="col.width"
......
...@@ -59,6 +59,7 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent imple ...@@ -59,6 +59,7 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent imple
@ViewChild('grid') public grid: GridComponent; @ViewChild('grid') public grid: GridComponent;
public widgetId: string; // Added widgetId property public widgetId: string; // Added widgetId property
private isPerspectiveApplied = false;
public data: DataManager = new DataManager([]); public data: DataManager = new DataManager([]);
public columns: any[] = []; public columns: any[] = [];
...@@ -104,11 +105,7 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent imple ...@@ -104,11 +105,7 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent imple
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
// Apply saved perspective if available // Perspective is now applied in onDataUpdate to ensure data is present.
// We do this in AfterViewInit to ensure the @ViewChild('grid') is available.
if (this.config.perspective) {
this.setWidgetState(this.config.perspective);
}
} }
applyInitialConfig(): void { applyInitialConfig(): void {
...@@ -163,7 +160,8 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent imple ...@@ -163,7 +160,8 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent imple
if (this.grid && state && state !== '{}') { if (this.grid && state && state !== '{}') {
try { try {
const stateObj = JSON.parse(state); const stateObj = JSON.parse(state);
(this.grid as any).setPersistData(stateObj); // Pass object instead of string this.grid.setProperties(stateObj);
this.isPerspectiveApplied = true;
} catch (e) { } catch (e) {
console.error("Error parsing perspective state for grid:", e); console.error("Error parsing perspective state for grid:", e);
} }
...@@ -183,6 +181,13 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent imple ...@@ -183,6 +181,13 @@ export class SyncfusionDatagridWidgetComponent extends BaseWidgetComponent imple
} }
} }
onDataBound(args: any): void {
// Apply perspective after data is loaded and rendered, but only once.
if (this.perspective && !this.isPerspectiveApplied) {
this.setWidgetState(this.perspective as string);
}
}
onReset(): void { onReset(): void {
this.title = 'Data Grid (Default)'; this.title = 'Data Grid (Default)';
this.data = new DataManager([]); this.data = new DataManager([]);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
[toolbar]="toolbar" [toolbar]="toolbar"
[displayOption]="displayOption" [displayOption]="displayOption"
[chartSettings]="chartSettings" [chartSettings]="chartSettings"
(dataBound)="onDataBound($event)"
height="100%"> height="100%">
</ejs-pivotview> </ejs-pivotview>
......
...@@ -19,6 +19,7 @@ export class SyncfusionPivotWidgetComponent extends BaseWidgetComponent implemen ...@@ -19,6 +19,7 @@ export class SyncfusionPivotWidgetComponent extends BaseWidgetComponent implemen
@ViewChild('pivotview') public pivotview: PivotViewComponent; @ViewChild('pivotview') public pivotview: PivotViewComponent;
public widgetId: string; public widgetId: string;
private isPerspectiveApplied = false;
public dataSourceSettings: { public dataSourceSettings: {
dataSource: DataManager; dataSource: DataManager;
...@@ -65,11 +66,7 @@ export class SyncfusionPivotWidgetComponent extends BaseWidgetComponent implemen ...@@ -65,11 +66,7 @@ export class SyncfusionPivotWidgetComponent extends BaseWidgetComponent implemen
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
// Apply saved perspective if available // Perspective is now applied in onDataUpdate to ensure data is present.
// We do this in AfterViewInit to ensure the @ViewChild('pivotview') is available.
if (this.config.perspective) {
this.setWidgetState(this.config.perspective);
}
} }
applyInitialConfig(): void { applyInitialConfig(): void {
...@@ -116,6 +113,7 @@ export class SyncfusionPivotWidgetComponent extends BaseWidgetComponent implemen ...@@ -116,6 +113,7 @@ export class SyncfusionPivotWidgetComponent extends BaseWidgetComponent implemen
if (this.pivotview) { if (this.pivotview) {
this.pivotview.dataSourceSettings = this.dataSourceSettings; this.pivotview.dataSourceSettings = this.dataSourceSettings;
} }
this.isPerspectiveApplied = true;
} catch (e) { } catch (e) {
console.error('Error applying pivot perspective state:', e); console.error('Error applying pivot perspective state:', e);
} }
...@@ -129,7 +127,17 @@ export class SyncfusionPivotWidgetComponent extends BaseWidgetComponent implemen ...@@ -129,7 +127,17 @@ export class SyncfusionPivotWidgetComponent extends BaseWidgetComponent implemen
}; };
if (this.pivotview) { if (this.pivotview) {
this.pivotview.dataSourceSettings.dataSource = new DataManager(data); this.pivotview.dataSourceSettings.dataSource = new DataManager(data);
this.pivotview.refresh(); // The refresh is implicitly handled by the dataBound event now
}
}
onDataBound(args: any): void {
if (this.pivotview) {
this.pivotview.refresh();
}
// Apply perspective after data is loaded and rendered, but only once.
if (this.perspective && !this.isPerspectiveApplied) {
this.setWidgetState(this.perspective as string);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment