ngx-mat-select-search
ngx-mat-select-search copied to clipboard
Bug: multiselect loading from server deselects all
Another issue when using multi-select, when you deselect the last one from filtered results, it will deselect all, included previous selected values stackblitz
adding the invisible option solves it, but causes a different issue with ctrl+a. instead of deselecting all (after selecting all) it selects all again.
Originally posted by @MoishyS in https://github.com/bithost-gmbh/ngx-mat-select-search/issues/311#issuecomment-937081816
we can solve the issue partially, by only showing options that are not in the filtered results stackblitz
this.hiddenOptions = this.filteredServerSideBanks.pipe(
map(
(values) =>
this.bankServerSideCtrl.value?.filter(
(a) => !values.find((b) => a.id == b.id)
) ?? []
)
);
it's still an issue when you deselect all, it will also deselect the options that aren't included in the filtered results.
Originally posted by @MoishyS in https://github.com/bithost-gmbh/ngx-mat-select-search/issues/311#issuecomment-937335482
ok, was able to solve it, by only showing the options if search ctrl is empty stackblitz
<ng-container *ngIf="!bankServerSideFilteringCtrl.value">
<mat-option *ngFor="let bank of bankServerSideCtrl.value"
[value]="bank" style="display: none">
{{ bank.name }}
</mat-option>
</ng-container>
also need to remove filter((search) => !!search)
as we won't hide the options when the select is visible, and will then have the issues with ctrl+a.
my question is, if this is the right way to fix, or do we have a better solution?
Originally posted by @MoishyS in https://github.com/bithost-gmbh/ngx-mat-select-search/issues/311#issuecomment-937413147
we can base it on mat-select openedChange
instead of bankServerSideFilteringCtrl.value, so we can leave the filter((search) => !!search)
@MoishyS so do you have a suggestion how to improve the example?
- we should add an example for multi-select
- currently each bank will have the same object reference, on a real server-side filtering it will be a new object, and will have to add a compareWith
- we should to the example how to add a default value
- we should add the current selected options when select is not open - to fix this bug
@MoishyS thanks for your suggestions. do you want to implement the changes you suggested?
Hi @macjohnny I can build a server side searching component if other guy not working on it
@mohammadaliez sure