ngx-mat-select-search icon indicating copy to clipboard operation
ngx-mat-select-search copied to clipboard

Bug: multiselect loading from server deselects all

Open macjohnny opened this issue 2 years ago • 8 comments

Another issue when using multi-select, when you deselect the last one from filtered results, it will deselect all, included previous selected values stackblitz yeqIVVnXAd-output

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

macjohnny avatar Oct 07 '21 06:10 macjohnny

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

macjohnny avatar Oct 07 '21 06:10 macjohnny

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

macjohnny avatar Oct 07 '21 06:10 macjohnny

we can base it on mat-select openedChange instead of bankServerSideFilteringCtrl.value, so we can leave the filter((search) => !!search)

MoishyS avatar Oct 07 '21 14:10 MoishyS

@MoishyS so do you have a suggestion how to improve the example?

macjohnny avatar Oct 07 '21 15:10 macjohnny

  • 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 avatar Oct 18 '21 21:10 MoishyS

@MoishyS thanks for your suggestions. do you want to implement the changes you suggested?

macjohnny avatar Oct 19 '21 05:10 macjohnny

Hi @macjohnny I can build a server side searching component if other guy not working on it

imohammadali avatar May 31 '23 19:05 imohammadali

@mohammadaliez sure

MoishyS avatar May 31 '23 19:05 MoishyS