Skip to content

Commit

Permalink
Synced from the Blueshift Repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Blueshift Staff committed Feb 20, 2024
1 parent adfe475 commit 3c04a0c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { MatSelectModule } from '@angular/material/select'
import { MatSidenavModule } from '@angular/material/sidenav'
import { MatSlideToggleModule } from '@angular/material/slide-toggle'
import { MatTooltipModule } from '@angular/material/tooltip'
import { MatSnackBarModule } from '@angular/material/snack-bar'

import { NgInitDirective } from './directives/ng-init.directive'
import { FloatingWindowComponent } from './floating-window/floating-window.component'
Expand All @@ -33,6 +34,7 @@ const materialModules = [
MatTooltipModule,
MatDividerModule,
MatSidenavModule,
MatSnackBarModule
]

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="row-thumb" #rowThumb>
<div class="row-thumb" #rowThumb (dblclick)="onRowThumbDblClick()">
<div class="action" (click)="a.onClick()" *ngFor="let a of cornerActions | async" [title]="a.tooltip | async">
<mat-icon [svgIcon]="(a.icon | async) ?? ''"></mat-icon>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
display: flex;
align-items: center;
justify-content: flex-start;
user-select: none;

&.has-groups {
width: 54px;
Expand Down Expand Up @@ -168,6 +169,10 @@
color: var(--text-color);
}
}

&:hover {
background-color: var(--highlight-color);
}
}

.grid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import { IGridConfiguration, IGridDataSource, IGridSelectionSlice } from '../../
import { AutoUnsubscribe } from '../../utils/auto-unsubscribe'
import { removeNullish } from '../../utils/custom-rxjs/remove-nullish'
import { WINDOW } from '../../utils/window'
import { GridCellCoordinates } from '../../typings/interfaces/implementations'
import { ExcelFormatter } from '../../utils/excel-formatter.class'
import { Clipboard } from '../../utils/clipboard.class'
import { MatSnackBar } from '@angular/material/snack-bar'

@Component({
selector: 'data-grid',
Expand Down Expand Up @@ -67,6 +71,38 @@ export class DataGridComponent extends AutoUnsubscribe implements OnInit, OnChan

@ViewChild('rowThumb', { static: true }) private rowThumb!: ElementRef<HTMLDivElement>

async onRowThumbDblClick() {

// Copy entire grid + headers to clipboard
const firstRow = this.gridController.dataSource.rows.latestValue[0]
const lastRow = this.gridController.dataSource.rows.latestValue[this.gridController.dataSource.rows.latestValue.length - 1]

const firstColumn = this.gridController.dataSource.columns[0]
const lastColumn = this.gridController.dataSource.columns[this.gridController.dataSource.columns.length - 1]

const startPos = new GridCellCoordinates(firstRow.rowKey, firstColumn.columnKey)
const endPos = new GridCellCoordinates(lastRow.rowKey, lastColumn.columnKey)

const selection = this.gridController.selection.CreateSelectionStateFromCoordinates.run([startPos, endPos])
selection.currentSelection.addRange(startPos, endPos)
const slice = this.gridController.selection.GetSelectionSlice.run(selection.currentSelection)

if (slice) {
const formatter = new ExcelFormatter(this.gridController, slice)
const html = formatter.toExcelHTML(true)
const plain = formatter.toPlainText(true)
await new Clipboard()
.setHTML(html)
.setPlainText(plain)
.write()
this._gridEvents.GridDataCopiedEvent.emit(true)

this.snack.open(
this.localizations.getLocalizedString("locGridCopiedToClipboard"),
this.localizations.getLocalizedString("locClose"), { duration: 3000 });
}
}

constructor(
@Inject(WINDOW) private _window: Window,
private readonly cd : ChangeDetectorRef,
Expand All @@ -76,7 +112,8 @@ export class DataGridComponent extends AutoUnsubscribe implements OnInit, OnChan
public readonly events : GridEventsService,
public readonly localizations : LocalizationService,
private readonly ctxService : GridContextMenuService,
public readonly multiEdit : GridMultiCellEditService
public readonly multiEdit : GridMultiCellEditService,
public readonly snack : MatSnackBar
) { super() }

ngOnInit(): void {
Expand Down

0 comments on commit 3c04a0c

Please sign in to comment.