有没有办法在 ng-select 上搜索时提供自定义排序?

Kau*_*nki 5 angular-ngselect angular

我遇到的情况是,我需要在 ng-select 下搜索时根据自定义逻辑对数据进行排序。可以选择使用 [searchFn] 跨多个字段进行搜索,但我需要根据我的自定义逻辑对匹配结果进行排序。

  1. 这可能吗 ?
  2. 请分享一些最初的理想如何实现?

ng-select:https://github.com/ng-select/ng-select

Sam*_*Sam 1

您可以侦听搜索事件并触发自定义函数来过滤数据集,然后修改 ng-select 具有的数据集。如果没有搜索到任何内容,您将需要管理重新填充下拉列表!

<ng-select (search)="onSearch($event)" [items]="data"></ng-select>

onSearch(e) {
    // Do your custom filtering here to the total dataset and then reassign.
    this.data = filtered_data;
}
Run Code Online (Sandbox Code Playgroud)