|
1 | | -import { Component, OnInit, ViewEncapsulation } from '@angular/core'; |
| 1 | +import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; |
2 | 2 | import { HttpClient } from '@angular/common/http'; |
3 | 3 | import { ExcelExportService } from '@slickgrid-universal/excel-export'; |
4 | 4 | import { SlickCompositeEditor, SlickCompositeEditorComponent } from '@slickgrid-universal/composite-editor-component'; |
@@ -36,7 +36,7 @@ const URL_COUNTRIES_COLLECTION = 'assets/data/countries.json'; |
36 | 36 | * @returns {boolean} isEditable |
37 | 37 | */ |
38 | 38 | function checkItemIsEditable(dataContext: any, columnDef: Column, grid: SlickGrid) { |
39 | | - const gridOptions = grid && grid.getOptions && grid.getOptions(); |
| 39 | + const gridOptions = grid?.getOptions(); |
40 | 40 | const hasEditor = columnDef.editor; |
41 | 41 | const isGridEditable = gridOptions.editable; |
42 | 42 | let isEditable = !!(isGridEditable && hasEditor); |
@@ -83,7 +83,8 @@ const myCustomTitleValidator = (value: any, args: any) => { |
83 | 83 | styleUrls: ['./grid-composite-editor.component.scss'], |
84 | 84 | encapsulation: ViewEncapsulation.None, |
85 | 85 | }) |
86 | | -export class GridCompositeEditorComponent implements OnInit { |
| 86 | +export class GridCompositeEditorComponent implements OnDestroy, OnInit { |
| 87 | + private _darkModeGrid = false; |
87 | 88 | title = 'Example 30: Composite Editor Modal'; |
88 | 89 | subTitle = `Composite Editor allows you to Create, Clone, Edit, Mass Update & Mass Selection Changes inside a nice Modal Window. |
89 | 90 | <br>The modal is simply populated by looping through your column definition list and also uses a lot of the same logic as inline editing (see <a href="https://ghiscoding.gitbook.io/angular-slickgrid/grid-functionalities/composite-editor-modal" target="_blank">Composite Editor - Wiki</a>.)`; |
@@ -122,6 +123,11 @@ export class GridCompositeEditorComponent implements OnInit { |
122 | 123 | this.dataset = this.loadData(NB_ITEMS); |
123 | 124 | } |
124 | 125 |
|
| 126 | + ngOnDestroy() { |
| 127 | + document.querySelector('.panel-wm-content')!.classList.remove('dark-mode'); |
| 128 | + document.querySelector<HTMLDivElement>('#demo-container')!.dataset.bsTheme = 'light'; |
| 129 | + } |
| 130 | + |
125 | 131 | prepareGrid() { |
126 | 132 | this.columnDefinitions = [ |
127 | 133 | { |
@@ -378,6 +384,7 @@ export class GridCompositeEditorComponent implements OnInit { |
378 | 384 | container: '#demo-container', |
379 | 385 | rightPadding: 10 |
380 | 386 | }, |
| 387 | + darkMode: this._darkModeGrid, |
381 | 388 | enableAutoSizeColumns: true, |
382 | 389 | enableAutoResize: true, |
383 | 390 | showCustomFooter: true, |
@@ -615,6 +622,11 @@ export class GridCompositeEditorComponent implements OnInit { |
615 | 622 | resetFormButtonIconCssClass: 'fa fa-undo', |
616 | 623 | onClose: () => Promise.resolve(confirm('You have unsaved changes, are you sure you want to close this window?')), |
617 | 624 | onError: (error) => alert(error.message), |
| 625 | + onRendered: (modalElm) => { |
| 626 | + // Bootstrap requires extra attribute when toggling Dark Mode (data-bs-theme="dark") |
| 627 | + // we need to manually add this attribute ourselve before opening the Composite Editor Modal |
| 628 | + modalElm.dataset.bsTheme = this._darkModeGrid ? 'dark' : 'light'; |
| 629 | + }, |
618 | 630 | onSave: (formValues, _selection, dataContext) => { |
619 | 631 | const serverResponseDelay = 50; |
620 | 632 |
|
@@ -750,6 +762,18 @@ export class GridCompositeEditorComponent implements OnInit { |
750 | 762 | this.editQueue = []; |
751 | 763 | } |
752 | 764 |
|
| 765 | + toggleDarkModeGrid() { |
| 766 | + this._darkModeGrid = !this._darkModeGrid; |
| 767 | + if (this._darkModeGrid) { |
| 768 | + document.querySelector<HTMLDivElement>('.panel-wm-content')!.classList.add('dark-mode'); |
| 769 | + document.querySelector<HTMLDivElement>('#demo-container')!.dataset.bsTheme = 'dark'; |
| 770 | + } else { |
| 771 | + document.querySelector('.panel-wm-content')!.classList.remove('dark-mode'); |
| 772 | + document.querySelector<HTMLDivElement>('#demo-container')!.dataset.bsTheme = 'light'; |
| 773 | + } |
| 774 | + this.angularGrid.slickGrid?.setOptions({ darkMode: this._darkModeGrid }); |
| 775 | + } |
| 776 | + |
753 | 777 | mockProducts() { |
754 | 778 | return [ |
755 | 779 | { |
|
0 commit comments