All files / src/components/tek-grid grouped-data-selector.ts

100% Statements 21/21
100% Branches 8/8
100% Functions 4/4
100% Lines 19/19

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  112x     112x       9x   8x 8x   8x 3x 6x 6x 3x     3x     5x 13x   12x 12x 11x           10x 3x   7x      
import { IDictionary } from '@zeedhi/core';
import { DataSelector, IDataSelector, IGrid } from '..';
import { IGroupedDataManager } from './interfaces';
 
export class GroupedDataSelector extends DataSelector implements IDataSelector {
	protected declare iterable: IGrid & IGroupedDataManager;
 
	public selectAll(isSelected: boolean) {
		if (!this.iterable.selectable) return;
 
		this.iterable.selectionState = { allSelected: isSelected, except: [] };
		const data = this.getData();
 
		if (!isSelected) {
			data.forEach((row: IDictionary) => {
				const index = this.iterable.selectedRows.indexOf(row);
				if (index > -1) {
					this.iterable.selectedRows.splice(index, 1);
				}
			});
			return;
		}
 
		data.forEach((row: IDictionary) => {
			if (this.callDisableSelection(row)) return;
 
			const key = this.iterable.getRowKey(row);
			if (key && this.iterable.selectedRows.indexOf(row) === -1) {
				this.iterable.selectedRows.push(row);
			}
		});
	}
 
	private getData() {
		if (this.iterable.isGrouped()) {
			return this.iterable.getGroupedData();
		}
		return this.iterable.getData();
	}
}