diff --git a/libs/mix-share/src/modules/database/database-data/database-data.component.html b/libs/mix-share/src/modules/database/database-data/database-data.component.html index 45a78aec..3be8a3aa 100644 --- a/libs/mix-share/src/modules/database/database-data/database-data.component.html +++ b/libs/mix-share/src/modules/database/database-data/database-data.component.html @@ -126,6 +126,7 @@ [rowDragManaged]="true" [rowSelection]="'multiple'" [suppressMoveWhenRowDragging]="true" + (cellValueChanged)="cellValueChanged($event)" (gridReady)="onGridReady($event)" (selectionChanged)="onSelectionChanged()" style="width: 100%; height: 100%"> diff --git a/libs/mix-share/src/modules/database/database-data/database-data.component.ts b/libs/mix-share/src/modules/database/database-data/database-data.component.ts index cca13122..30adbe19 100644 --- a/libs/mix-share/src/modules/database/database-data/database-data.component.ts +++ b/libs/mix-share/src/modules/database/database-data/database-data.component.ts @@ -34,7 +34,12 @@ import { TuiReorderModule, TuiTableModule } from '@taiga-ui/addon-table'; import { TuiDestroyService } from '@taiga-ui/cdk'; import { TuiCheckboxModule, TuiPaginationModule } from '@taiga-ui/kit'; import { AgGridModule } from 'ag-grid-angular'; -import { ColDef, GridApi, GridReadyEvent } from 'ag-grid-community'; +import { + CellValueChangedEvent, + ColDef, + GridApi, + GridReadyEvent, +} from 'ag-grid-community'; import { Observable, Subject, @@ -115,6 +120,7 @@ export class DatabaseDataComponent sortable: false, headerCheckboxSelection: true, checkboxSelection: true, + editable: true, headerComponentParams: { displayName: '', columnType: 'check', @@ -136,6 +142,7 @@ export class DatabaseDataComponent public readonly defaultColDef: ColDef = { sortable: true, resizable: true, + editable: true, width: 250, }; @@ -200,6 +207,22 @@ export class DatabaseDataComponent }); } + public cellValueChanged(event: CellValueChangedEvent) { + const data = event.data as MixDynamicData; + Object.keys(data).forEach((key) => { + if (data[key] === null) { + delete data[key]; + } + }); + + this.mixApi.databaseApi + .saveData(this.dbSysName, data.id ?? -1, data) + .pipe(toastObserverProcessing(this.toast)) + .subscribe((result) => { + this.store.updateData(event.rowIndex || 0, result as MixDynamicData); + }); + } + public onSelectionChanged() { this.selectedItems = this.gridApi.getSelectedRows(); }