src/lib/select-row/select-row.service.ts
Properties |
|
Methods |
Accessors |
constructor(options: SelectRowOptions<Data> | null)
|
||||||
Defined in src/lib/select-row/select-row.service.ts:24
|
||||||
Parameters :
|
clear |
clear()
|
Defined in src/lib/select-row/select-row.service.ts:42
|
Returns :
void
|
compareWith | |||||||||
compareWith(a: Data, b: Data)
|
|||||||||
Defined in src/lib/select-row/select-row.service.ts:46
|
|||||||||
Parameters :
Returns :
boolean
|
Public selectedRows$ |
Type : Observable<Data[]>
|
Defined in src/lib/select-row/select-row.service.ts:18
|
Public Readonly selectionModel |
Default value : new SelectionModel<Data>(true)
|
Defined in src/lib/select-row/select-row.service.ts:20
|
selectedRows |
getselectedRows()
|
Defined in src/lib/select-row/select-row.service.ts:22
|
import {
Inject,
Injectable,
Optional,
} from '@angular/core';
import {
getIdentifierPropertyValue,
hasIdentifierProperty,
} from '@rxap/utilities';
import type { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { SelectRowOptions } from './select-row.options';
import { SelectionModel } from './selection-model';
import { RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS } from './tokens';
@Injectable()
export class SelectRowService<Data = unknown> {
public selectedRows$: Observable<Data[]>;
public readonly selectionModel = new SelectionModel<Data>(true);
public get selectedRows(): Data[] {
return this.selectionModel.selected;
}
constructor(
@Optional()
@Inject(RXAP_MATERIAL_TABLE_SYSTEM_SELECT_ROW_OPTIONS)
options: SelectRowOptions<Data> | null = null,
) {
this.selectionModel = new SelectionModel<Data>(
options?.multiple,
options?.selected,
options?.emitChanges,
options?.compareWith ?? this.compareWith,
);
this.selectedRows$ = this.selectionModel.changed.pipe(
map(() => this.selectionModel.selected),
);
}
clear() {
this.selectionModel.clear();
}
compareWith(a: Data, b: Data): boolean {
if (a === b) {
return true;
}
if (hasIdentifierProperty(a) && hasIdentifierProperty(b)) {
return getIdentifierPropertyValue(a) === getIdentifierPropertyValue(b);
}
return false;
}
}