Allow resizing and saving column widths

This commit is contained in:
Garrett Mills 2020-11-12 14:18:08 -06:00
parent a5dc7f7a19
commit c4e236a0bf
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
2 changed files with 45 additions and 3 deletions

View File

@ -23,6 +23,8 @@
suppressMovableColumns="true" suppressMovableColumns="true"
(rowClicked)="onRowClicked($event)" (rowClicked)="onRowClicked($event)"
(cellValueChanged)="onCellValueChanged()" (cellValueChanged)="onCellValueChanged()"
(gridReady)="onGridReady($event)"
(columnResized)="onColumnResize($event)"
#agGridElement #agGridElement
></ag-grid-angular> ></ag-grid-angular>
</div> </div>

View File

@ -15,7 +15,7 @@ import {BooleanRendererComponent} from './renderers/boolean-renderer.component';
import {EditorNodeContract} from '../../nodes/EditorNode.contract'; import {EditorNodeContract} from '../../nodes/EditorNode.contract';
import {EditorService} from '../../../service/editor.service'; import {EditorService} from '../../../service/editor.service';
import {WysiwygEditorComponent} from './editors/wysiwyg/wysiwyg-editor.component'; import {WysiwygEditorComponent} from './editors/wysiwyg/wysiwyg-editor.component';
import {debounce} from '../../../utility'; import {debounce, debug} from '../../../utility';
@Component({ @Component({
selector: 'editor-database', selector: 'editor-database',
@ -86,6 +86,25 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit {
}); });
} }
onGridReady($event) {
}
onColumnResize($event) {
if ( $event.source === 'uiColumnDragged' && $event.finished ) {
debug('Column resized: ', $event);
const state = $event.columnApi.getColumnState().find(x => x.colId === $event.column.colId );
if ( state ) {
const colDef = this.columnDefs.find(x => x.field === $event.column.colId);
if ( colDef ) {
colDef.width = state.width;
this.dirty = true;
this.triggerSaveDebounce();
}
}
}
}
onCellValueChanged() { onCellValueChanged() {
if ( !this.isInitialLoad ) { if ( !this.isInitialLoad ) {
this.dirty = true; this.dirty = true;
@ -161,6 +180,11 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit {
this.columnDefs = data.map(x => { this.columnDefs = data.map(x => {
x.editable = !this.readonly; x.editable = !this.readonly;
x.minWidth = 150; x.minWidth = 150;
x.resizable = true;
if ( x.additionalData?.width ) {
x.width = x.additionalData.width;
}
// Set editors and renderers for different types // Set editors and renderers for different types
if ( x.Type === 'text' ) { if ( x.Type === 'text' ) {
@ -186,7 +210,9 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit {
} else if ( x.Type === 'index' ) { } else if ( x.Type === 'index' ) {
x.editable = false; x.editable = false;
x.suppressSizeToFit = true; x.suppressSizeToFit = true;
if ( !x.width ) {
x.width = 80; x.width = 80;
}
x.minWidth = 80; x.minWidth = 80;
} else if ( x.Type === 'wysiwyg' ) { } else if ( x.Type === 'wysiwyg' ) {
x.cellEditorFramework = WysiwygEditorComponent; x.cellEditorFramework = WysiwygEditorComponent;
@ -253,9 +279,23 @@ export class DatabaseComponent extends EditorNodeContract implements OnInit {
await this.api.deleteDatabase(this.page.UUID, this.node.UUID, this.node.Value.Value); await this.api.deleteDatabase(this.page.UUID, this.node.UUID, this.node.Value.Value);
} }
public getSaveColumns() {
return this.columnDefs.map(x => {
if ( !x.additionalData ) {
x.additionalData = {};
}
if ( x.width ) {
x.additionalData.width = x.width;
}
return x;
});
}
public async performSave(): Promise<void> { public async performSave(): Promise<void> {
// Save the columns first // Save the columns first
await this.api.saveDatabaseColumns(this.page.UUID, this.node.UUID, this.node.Value.Value, this.columnDefs); await this.api.saveDatabaseColumns(this.page.UUID, this.node.UUID, this.node.Value.Value, this.getSaveColumns());
// Save the data // Save the data
const rows = await this.api.saveDatabaseEntries(this.page.UUID, this.node.UUID, this.node.Value.Value, this.rowData); const rows = await this.api.saveDatabaseEntries(this.page.UUID, this.node.UUID, this.node.Value.Value, this.rowData);