ng_bootstrap icon indicating copy to clipboard operation
ng_bootstrap copied to clipboard

Typeahead should allow users to provide their own matching function

Open wz2b opened this issue 9 years ago • 1 comments

It would be a nice feature addition to let typeahead users specify their own matching filter (where they provide you with a function). This would facilitate:

  • Searching on more than one property of the object (e.g. object has a 'name' and a 'description')
  • Other custom matching, such as case-insensitivity or "startsWith"

wz2b avatar Aug 04 '16 20:08 wz2b

I can KIND of work around this by using the asynchronous loader interface and do the filtering there:

  Future<List<String>>  fetchData(String query) async {
    String search = query.toLowerCase();
    List<Tag> allTags = await tagCache.getAll();

    return allTags.where( (Tag item) =>
        item.name?.toLowerCase()?.contains(search) ||
            item.description?.toLowerCase()?.contains(search)
    ).map((Tag t) => t.name);
  }

this combines the concept of a user-configurable item filter with the asynchronous loading, and the pattern works even if you don't need asynchronous loading at all (you just pretend you do but return the filtered list).

So maybe the developers will decide this isn't that adding the ability to specify a filter is not that important.

wz2b avatar Aug 04 '16 21:08 wz2b