All files / src/components/tek-grid tek-grid-events.ts

100% Statements 20/20
100% Branches 5/5
100% Functions 6/6
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106  112x       112x           109x   109x     109x 109x       1x                     3x 1x   1x               3x                   3x 1x               3x       2x 1x               2x                     3x 2x               1x                    
import { IDictionary } from '@zeedhi/core';
import { GridEditableEvents } from '../zd-grid-editable';
import { ITekGrid, ITekGridEvents, ITekGridSummary } from './interfaces';
import { TekGridColumn } from './tek-grid-column';
 
export class TekGridEvents extends GridEditableEvents implements ITekGridEvents {
	protected tekGrid: ITekGrid;
 
	/**
	 * Flag to prevent row click
	 */
	protected preventRowClick = false;
 
	protected preventRowDoubleClick = false;
 
	constructor(tekGrid: ITekGrid) {
		super(tekGrid);
		this.tekGrid = tekGrid;
	}
 
	calcSummary(column: TekGridColumn, summary: ITekGridSummary, row: IDictionary): void {
		this.tekGrid.callEvent('calcSummary', {
			component: this.tekGrid,
			column,
			columnName: column.name,
			summary,
			row,
			rowValue: row[column.name],
		});
	}
 
	public rowDoubleClick(row: IDictionary<any>, event: Event, element: HTMLElement) {
		if (!this.preventRowDoubleClick) {
			this.tekGrid.datasource.currentRow = row;
 
			this.tekGrid.callEvent('rowDoubleClick', {
				event,
				element,
				row,
				component: this.tekGrid,
				column: undefined,
			});
		}
		this.preventRowDoubleClick = false;
	}
 
	/**
	 * Dispatches group row click event
	 * @param row Grid row
	 * @param event DOM event
	 * @param element DOM Element
	 */
	public groupRowClick(row: IDictionary<any>, event: Event, element: HTMLElement) {
		if (!this.preventRowClick) {
			this.tekGrid.callEvent('groupRowClick', {
				event,
				element,
				row,
				component: this.tekGrid,
				column: undefined,
			});
		}
		this.preventRowClick = false;
	}
 
	public groupRowDoubleClick(row: IDictionary<any>, event: Event, element: HTMLElement) {
		if (!this.preventRowDoubleClick) {
			this.tekGrid.callEvent('groupRowDoubleClick', {
				event,
				element,
				row,
				component: this.tekGrid,
				column: undefined,
			});
		}
		this.preventRowDoubleClick = false;
	}
 
	/**
	 * Dispatches group select/unselect event
	 * @param row Group row
	 * @param isSelected Row is selected
	 * @param event DOM event
	 * @param element DOM Element
	 */
	public selectGroupClick(row: IDictionary<any>, isSelected: boolean, event: Event, element: HTMLElement) {
		if (isSelected) {
			this.tekGrid.callEvent('groupSelected', {
				event,
				element,
				row,
				component: this.tekGrid,
				column: undefined,
			});
		} else {
			this.tekGrid.callEvent('groupUnselected', {
				event,
				element,
				row,
				component: this.tekGrid,
				column: undefined,
			});
		}
	}
}