</div>
@if (selectionModel.items) {
<div class="items" #buttonItems>
- @for (item of selectionModel.itemsSorted | filter: filterText:'name'; track item; let i = $index) {
+ @for (item of selectionModel.items | filter: filterText:'name'; track item; let i = $index) {
@if (allowSelectNone || item.id) {
<pngx-toggleable-dropdown-button
[item]="item" [hideCount]="hideCount(item)" [state]="selectionModel.get(item.id)" [count]="getUpdatedDocumentCount(item.id)" (toggled)="selectionModel.toggle(item.id)" (exclude)="excludeClicked(item.id)" (click)="setButtonItemIndex(i - 1)" [disabled]="disabled">
</div>
}
@if (editing) {
- @if ((selectionModel.itemsSorted | filter: filterText:'name').length === 0 && createRef !== undefined) {
+ @if ((selectionModel.items | filter: filterText:'name').length === 0 && createRef !== undefined) {
<button class="list-group-item list-group-item-action bg-light" (click)="createClicked()" [disabled]="disabled">
<small class="ms-2"><ng-container i18n>Create</ng-container> "{{filterText}}"</small>
<i-bs width="1.5em" height="1em" name="plus"></i-bs>
</button>
}
- @if ((selectionModel.itemsSorted | filter: filterText:'name').length > 0) {
+ @if ((selectionModel.items | filter: filterText:'name').length > 0) {
<button class="list-group-item list-group-item-action bg-light" (click)="applyClicked()" [disabled]="!modelIsDirty || disabled">
<small class="ms-2" [ngClass]="{'fw-bold': modelIsDirty}" i18n>Apply</small>
<i-bs width="1.5em" height="1em" name="arrow-right"></i-bs>
component.selectionModel = selectionModel
selectionModel.toggle(items[1].id)
selectionModel.apply()
- expect(selectionModel.itemsSorted).toEqual([
+ expect(selectionModel.items).toEqual([
nullItem,
{ id: null, name: 'Null B' },
items[1],
private _intersection: Intersection = Intersection.Include
temporaryIntersection: Intersection = this._intersection
- items: MatchingModel[] = []
+ private _items: MatchingModel[] = []
+ get items(): MatchingModel[] {
+ return this._items
+ }
+
+ set items(items: MatchingModel[]) {
+ this._items = items
+ this.sortItems()
+ }
- get itemsSorted(): MatchingModel[] {
- // TODO: this is getting called very often
- return this.items.sort((a, b) => {
+ private sortItems() {
+ this._items.sort((a, b) => {
if (a.id == null && b.id != null) {
return -1
} else if (a.id != null && b.id == null) {
})
this._logicalOperator = this.temporaryLogicalOperator
this._intersection = this.temporaryIntersection
+ this.sortItems()
}
reset(complete: boolean = false) {