packages/core/src/lib/selection/selection.ts
Extension of List that keeps track of selected items. It can keep track of items via identifier property even if the object references are being replaced, e.g. when reloading a set if items. It supports solo and multiple selection.
Properties |
Methods |
|
| Protected change |
Type : Subject<List<T>>
|
Default value : new Subject()
|
|
Inherited from
List
|
|
Defined in
List:33
|
|
Subject that should be nexted when loading is finished |
| Public change$ |
Type : Observable<List<T>>
|
Default value : this.change.asObservable()
|
|
Inherited from
List
|
|
Defined in
List:35
|
|
Observable that is nexted when the list has changed. |
| Public config |
Type : ListConfig<T>
|
|
Inherited from
List
|
|
Defined in
List:23
|
|
The List Configuration, click on ListConfig for details. Can be given an optional ListConfig. |
| Public fields |
Type : Array<Field>
|
|
Inherited from
List
|
|
Defined in
List:19
|
|
Array of Properties that are relevant for each item. The fields are populated on construction via getFields method. |
| groups |
Type : []
|
Default value : []
|
|
Inherited from
List
|
|
Defined in
List:27
|
|
Current Value Groups (Different Unique Values). |
| Public page |
Type : Array<Item<T>>
|
Default value : []
|
|
Inherited from
List
|
|
Defined in
List:31
|
|
The items of the current page |
| Public pagination |
Type : Pagination<T>
|
|
Inherited from
List
|
|
Defined in
List:29
|
|
The list's pagination (Optional) |
| Public items |
Type : Array<T>
|
|
Inherited from
List
|
|
Defined in
List:10
|
|
The items must all have the same type T. |
| Protected update |
Type : Subject<Collection<T>>
|
Default value : new Subject()
|
|
Inherited from
List
|
|
Defined in
List:12
|
|
Subject that is nexted when the items update |
| Public update$ |
Type : Observable<Collection<T>>
|
Default value : this.update.asObservable()
|
|
Inherited from
List
|
|
Defined in
List:14
|
|
Subject that is nexted when the items change |
| Public items |
Type : Array<T>
|
|
Inherited from
Collection
|
|
Defined in
Collection:10
|
|
The items must all have the same type T. |
| Protected update |
Type : Subject<Collection<T>>
|
Default value : new Subject()
|
|
Inherited from
Collection
|
|
Defined in
Collection:12
|
|
Subject that is nexted when the items update |
| Public update$ |
Type : Observable<Collection<T>>
|
Default value : this.update.asObservable()
|
|
Inherited from
Collection
|
|
Defined in
Collection:14
|
|
Subject that is nexted when the items change |
| flipAll | ||||
flipAll(items)
|
||||
|
Flips all items.
Parameters :
Returns :
this
|
| getValue | ||||||||
getValue(solo: boolean)
|
||||||||
|
Returns an Array containing the current value. If an identifier is set, the array will consist of the identifier values, if not, it will resolve the item contents.
Parameters :
Returns :
any
|
| has | ||||||
has(item: Item
|
||||||
|
Parameters :
Returns :
any
|
| index | ||||||
index(item: Item
|
||||||
|
Returns the index of the given item or an item that has the same identifier or value.
Parameters :
Returns :
number
|
| select | ||||||||||||
select(item: Item
|
||||||||||||
|
Adds item to selection. If solo is true, all other items will be removed.
Parameters :
Returns :
void
|
| toggle | ||||||||||||||||
toggle(item: Item
|
||||||||||||||||
|
Toggle item in and out of selection. The solo property will change the behaviour like you would expect it to behave :)
Parameters :
Returns :
any
|
| toggleAll | ||||||||||||
toggleAll(items: Array
|
||||||||||||
|
Toggle multiple items. You can control if the items should be kept, flipped, or be kept unique
Parameters :
Returns :
this
|
| add | ||||||||||||||||
add(item: Item
|
||||||||||||||||
|
Inherited from
List
|
||||||||||||||||
|
Defined in
List:79
|
||||||||||||||||
|
Adds the given item to the list and assigns the list config to the item
Parameters :
Returns :
any
|
| clearFilter | ||||||
clearFilter(property?: string)
|
||||||
|
Inherited from
List
|
||||||
|
Defined in
List:180
|
||||||
|
Clears the filter for given property or all properties if none given.
Parameters :
Returns :
void
|
| Public filter | ||||||||||||||||
filter(property: string, value: any, operator: string)
|
||||||||||||||||
|
Inherited from
List
|
||||||||||||||||
|
Defined in
List:141
|
||||||||||||||||
|
Filters the list after the given property and value
Parameters :
Returns :
void
|
| Public filterableFields |
filterableFields()
|
|
Inherited from
List
|
|
Defined in
List:303
|
|
Returns an array of all sortable fields
Returns :
any
|
| Protected getFields |
getFields()
|
|
Inherited from
List
|
|
Defined in
List:88
|
|
Distills Array of item properties. Either uses keys of config.fields or parses the item properties directly.
Returns :
Array<Field>
|
| getFilterValue | ||||||||||||
getFilterValue(property?: string, filterOptions)
|
||||||||||||
|
Inherited from
List
|
||||||||||||
|
Defined in
List:213
|
||||||||||||
|
Returns the filter
Parameters :
Returns :
any
|
| groupBy | ||||
groupBy(property)
|
||||
|
Inherited from
List
|
||||
|
Defined in
List:266
|
||||
|
Returns an Array of all unique values of the given property
Parameters :
Returns :
void
|
| Protected hideOverflowFields |
hideOverflowFields()
|
|
Inherited from
List
|
|
Defined in
List:111
|
|
Sets all fields that exceed the maxColumns to hidden
Returns :
void
|
| id | ||||||
id(identifier: any)
|
||||||
|
Inherited from
List
|
||||||
|
Defined in
List:126
|
||||||
|
Resolves the item with the given Array index or identifier (if configured)
Parameters :
Returns :
Item<T>
|
| isEmptyFilter | ||||||
isEmptyFilter(query: null | undefined | string | Array
|
||||||
|
Inherited from
List
|
||||||
|
Defined in
List:191
|
||||||
|
Helper function. Returns true if the given query value is empty (also recognizes empty array)
Parameters :
Returns :
boolean
|
| isFiltered | ||||||||||||
isFiltered(property?: string, filterOptions)
|
||||||||||||
|
Inherited from
List
|
||||||||||||
|
Defined in
List:202
|
||||||||||||
|
Returns true if the given property has a filter set. If no property is given it returns true when no property has a filter.
Parameters :
Returns :
boolean
|
| Public isOverTheMax | ||||||
isOverTheMax(field: Field)
|
||||||
|
Inherited from
List
|
||||||
|
Defined in
List:307
|
||||||
|
Returns true if the given field index in the visible fields is higher than maxColumns.
Parameters :
Returns :
boolean
|
| Public isSorted |
isSorted(property: string, desc?: boolean)
|
|
Inherited from
List
|
|
Defined in
List:244
|
|
Returns true if the given sort state is active. You can either just check for a property + desc flag
Returns :
boolean
|
| Public load | ||||||
load(config?: ListConfig
|
||||||
|
Inherited from
List
|
||||||
|
Defined in
List:69
|
||||||
|
Loads the list page with the given config or, if none given, uses the current config. Reapplies grouping (if any) and calls the change Subject.
Parameters :
Returns :
void
|
| setFilter | ||||||||
setFilter(filterOptions: object)
|
||||||||
|
Inherited from
List
|
||||||||
|
Defined in
List:159
|
||||||||
|
Parameters :
Returns :
void
|
| Public sortableFields |
sortableFields()
|
|
Inherited from
List
|
|
Defined in
List:299
|
|
Returns an array of all sortable fields
Returns :
any
|
| Protected sortProperty |
sortProperty(property: string, desc?: boolean)
|
|
Inherited from
List
|
|
Defined in
List:224
|
|
Changes the config's sort variables to reflect the given sorting
Returns :
void
|
| toggleSelectMode |
toggleSelectMode()
|
|
Inherited from
List
|
|
Defined in
List:258
|
|
Toggles selectMode of list config
Returns :
void
|
| toggleSort |
toggleSort(property: string, desc?: boolean)
|
|
Inherited from
List
|
|
Defined in
List:252
|
|
Sorts with given sorting, using the Sorter
Returns :
void
|
| Public toggleVisibility | ||||
toggleVisibility(field)
|
||||
|
Inherited from
List
|
||||
|
Defined in
List:105
|
||||
|
Parameters :
Returns :
void
|
| Public trackItem | ||||||
trackItem(index, item)
|
||||||
|
Inherited from
List
|
||||||
|
Defined in
List:295
|
||||||
|
Item tracking for *ngFor.
Parameters :
Returns :
any
|
| add |
add(item: T, unique?: boolean, event: boolean)
|
|
Inherited from
List
|
|
Defined in
List:71
|
|
Adds the given item to the Collection. If the unique flag is set, the item will only be added if it is not contained.
Example :
Returns :
boolean
|
| addAll | ||||||||||||||||
addAll(items: Array
|
||||||||||||||||
|
Inherited from
List
|
||||||||||||||||
|
Defined in
List:89
|
||||||||||||||||
|
Adds the given items to the Collection. If the unique flag is set, only items that are not contained will be added.
Parameters :
Example :
Returns :
void
|
| has | ||||||
has(item: T)
|
||||||
|
Inherited from
List
|
||||||
|
Defined in
List:42
|
||||||
|
Checks if the Collection contains the given item.
Parameters :
Example :
Returns :
boolean
|
| hasAll | ||||||||
hasAll(items: Array
|
||||||||
|
Inherited from
List
|
||||||||
|
Defined in
List:53
|
||||||||
|
Checks if the Collection contains all given items.
Parameters :
Example :
Returns :
boolean
|
| index | ||||||
index(item: T)
|
||||||
|
Inherited from
List
|
||||||
|
Defined in
List:31
|
||||||
|
Returns the index of the given item
Parameters :
Returns :
number
|
| isEmpty |
isEmpty()
|
|
Inherited from
List
|
|
Defined in
List:160
|
|
Returns true if the collection is empty
Returns :
boolean
|
| move |
move(item: T, index: number, event: boolean)
|
|
Inherited from
List
|
|
Defined in
List:165
|
|
Moves the given item to the given array index.
Returns :
void
|
| remove | ||||||||||||
remove(item: T, event: boolean)
|
||||||||||||
|
Inherited from
List
|
||||||||||||
|
Defined in
List:106
|
||||||||||||
|
Removes the given item from the Collection.
Parameters :
Example :
Returns :
boolean
|
| removeAll | ||||||||||||
removeAll(items?: Array
|
||||||||||||
|
Inherited from
List
|
||||||||||||
|
Defined in
List:123
|
||||||||||||
|
Removes all items from the Collection.
Parameters :
Example :
Returns :
void
|
| replaceWith | ||||||||||||
replaceWith(items: Array
|
||||||||||||
|
Inherited from
List
|
||||||||||||
|
Defined in
List:147
|
||||||||||||
|
Replaces all current items with the given items.
Parameters :
Returns :
void
|
| toggle | ||||||||||||
toggle(item: T, event: boolean)
|
||||||||||||
|
Inherited from
List
|
||||||||||||
|
Defined in
List:138
|
||||||||||||
|
Toggles the item in and out of collection
Parameters :
Returns :
void
|
| add |
add(item: T, unique?: boolean, event: boolean)
|
|
Inherited from
Collection
|
|
Defined in
Collection:71
|
|
Adds the given item to the Collection. If the unique flag is set, the item will only be added if it is not contained.
Example :
Returns :
boolean
|
| addAll | ||||||||||||||||
addAll(items: Array
|
||||||||||||||||
|
Inherited from
Collection
|
||||||||||||||||
|
Defined in
Collection:89
|
||||||||||||||||
|
Adds the given items to the Collection. If the unique flag is set, only items that are not contained will be added.
Parameters :
Example :
Returns :
void
|
| has | ||||||
has(item: T)
|
||||||
|
Inherited from
Collection
|
||||||
|
Defined in
Collection:42
|
||||||
|
Checks if the Collection contains the given item.
Parameters :
Example :
Returns :
boolean
|
| hasAll | ||||||||
hasAll(items: Array
|
||||||||
|
Inherited from
Collection
|
||||||||
|
Defined in
Collection:53
|
||||||||
|
Checks if the Collection contains all given items.
Parameters :
Example :
Returns :
boolean
|
| index | ||||||
index(item: T)
|
||||||
|
Inherited from
Collection
|
||||||
|
Defined in
Collection:31
|
||||||
|
Returns the index of the given item
Parameters :
Returns :
number
|
| isEmpty |
isEmpty()
|
|
Inherited from
Collection
|
|
Defined in
Collection:160
|
|
Returns true if the collection is empty
Returns :
boolean
|
| move |
move(item: T, index: number, event: boolean)
|
|
Inherited from
Collection
|
|
Defined in
Collection:165
|
|
Moves the given item to the given array index.
Returns :
void
|
| remove | ||||||||||||
remove(item: T, event: boolean)
|
||||||||||||
|
Inherited from
Collection
|
||||||||||||
|
Defined in
Collection:106
|
||||||||||||
|
Removes the given item from the Collection.
Parameters :
Example :
Returns :
boolean
|
| removeAll | ||||||||||||
removeAll(items?: Array
|
||||||||||||
|
Inherited from
Collection
|
||||||||||||
|
Defined in
Collection:123
|
||||||||||||
|
Removes all items from the Collection.
Parameters :
Example :
Returns :
void
|
| replaceWith | ||||||||||||
replaceWith(items: Array
|
||||||||||||
|
Inherited from
Collection
|
||||||||||||
|
Defined in
Collection:147
|
||||||||||||
|
Replaces all current items with the given items.
Parameters :
Returns :
void
|
| toggle | ||||||||||||
toggle(item: T, event: boolean)
|
||||||||||||
|
Inherited from
Collection
|
||||||||||||
|
Defined in
Collection:138
|
||||||||||||
|
Toggles the item in and out of collection
Parameters :
Returns :
void
|
Selection is a List with selection specific features:
import { Item } from '../item/item';
import { List } from '../list/list';
/**
* Extension of List that keeps track of selected items. It can keep track of items via identifier
* property even if the object references are being replaced, e.g. when reloading a set if items.
* It supports solo and multiple selection.
*/
export class Selection<T> extends List<T> {
/** Adds item to selection. If solo is true, all other items will be removed. */
select(item: Item<T>, solo = this.config.solo) {
if (solo) {
this.removeAll();
this.add(item);
} else {
this.add(item, true);
}
}
/** Returns the index of the given item or an item that has the same identifier or value. */
index(item: Item<T>): number {
if (this.config.identifier) {
return this.items.indexOf(this.id(item.resolve(this.config.identifier)));
}
return this.items.indexOf(this.items.find((i) => i.resolve() === item.resolve()));
}
has(item: Item<T>) {
return super.has(item) || this.index(item) !== -1;
}
/** Toggle item in and out of selection.
* The solo property will change the behaviour like you would expect it to behave :) */
toggle(item: Item<T>, solo = this.config.solo, event: boolean = true) {
if (!item) {
console.warn('toggle malicious item', item);
return;
}
if (!this.has(item)) {
if (solo) {
return this.replaceWith([item], event);
}
this.add(item, event);
} else if (solo) {
if (this.items.length > 1) {
// if multiple are selected => keep item
return this.replaceWith([item], event);
}
this.removeAll();
} else {
this.remove(item, event);
}
}
/** Toggle multiple items. You can control if the items should be kept, flipped, or be kept unique*/
toggleAll(items: Array<Item<T>>, flip?: boolean, keep?: boolean) {
items = items || [];
// items = Array.isArray(items) ? items : [items];
if (!flip && !keep && this.hasAll(items)) {
this.removeAll(items);
return this;
}
items.forEach((item) => {
if (flip) {
this.toggle(item, this.config.solo, false);
} else if (!this.hasAll(items)) {
this.add(item, true, false);
}
});
this.update.next(this);
return this;
}
/** Flips all items. */
flipAll(items) {
return this.toggleAll(items, true);
}
/** Returns an Array containing the current value. If an identifier is set, the array will consist of the identifier values,
* if not, it will resolve the item contents. */
getValue(solo: boolean = this.config.solo) {
const value = this.items.map((item) => (this.config.identifier ? item.id() : item.resolve()));
if (solo) {
return value.length ? value[0] : null;
}
return value;
}
}