### File

`src/lib/select-row/select-row.service.ts`

### Index

###### Properties

- Public selectedRows$
- Public Readonly selectionModel

###### Methods

- clear
- compareWith

###### Accessors

- selectedRows

### Constructor

`constructor(options: SelectRowOptions<Data> | null)`
Defined in src/lib/select-row/select-row.service.ts:24

Parameters :

Name | Type | Optional
options | `SelectRowOptions<Data> | null` | No

### Methods

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 :

Name | Type | Optional
a | `Data` | No
b | `Data` | No

Returns : `boolean`

### Properties

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

### Accessors

selectedRows
get `selectedRows()`
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;
      }

    }

# results matching ""

# No results matching ""