Skip to content

feat(typeahead): add using multiple sets of results at typeahead #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dessalines opened this issue Jul 26, 2016 · 13 comments
Open

feat(typeahead): add using multiple sets of results at typeahead #794

dessalines opened this issue Jul 26, 2016 · 13 comments

Comments

@dessalines
Copy link

I need to include multiple result sets in my search bar dropdown, for example, searching for songs, and albums. Is there any way to do this yet?

Example

@dessalines
Copy link
Author

Any updates on this, I could potentially do a PR if that's okay.

@adrianfaciu
Copy link

@tchoulihan I don't think there are any updates so far. So if you're able to help, it would be nice 😄

@mixomat
Copy link
Contributor

mixomat commented Oct 5, 2016

I'm working on grouped matches / result sets in this fork:
https://github.com/mixomat/ng2-bootstrap/tree/feat-typeahead-groups

I think the grouping would fix this feature request as well.

This is wip right now, created initial tests for the typeahead directive and the container component.
I'm almost ready for a PR for integration or further discussion / improvements.

@dessalines
Copy link
Author

dessalines commented Oct 5, 2016

My use case is fetching from 2 different endpoints, (or .json files) like twitter's example above.

This means it makes sense to make the object more embedded, so something like:

<input [(ngModel)]="typeaheadSelected"
  [typeahead]="[nbaTypeAhead, nhlTypeAhead]"
  class="form-control">
nbaTypeAhead: TypeAhead = {
  display: 'team',
  source: this.nbaTeams,
  templates: {
    header: '<h3 class="league-name">NBA Teams</h3>'
  },
  onSelect(selected): {
    ...
  }
};
nhlTypeAhead: TypeAhead = {
  display: 'team',
  source: this.nhlTeams,
  templates: {
    header: '<h3 class="league-name">NHL Teams</h3>'
  },
  onSelect(selected): {
    ...
  }
}

@mixomat
Copy link
Contributor

mixomat commented Oct 5, 2016

I was thinking about the approach to expose the Typeahead model class, but this would force the User to always provide the typeahead options as a complex object.

So the simple use case, where you just want to provide an array of strings without any grouping, gets more complicated.

@mixomat
Copy link
Contributor

mixomat commented Oct 6, 2016

@dessalines With the grouped approach you can still get this working by combining and flattening the datasets, once the fetch to the multiple data sources has completed.

Something like Observable.combineLatest(nbaData, nhlData), () => ...).flapMap(...).toArray() should do the trick.

@Martin-Luft
Copy link
Contributor

@dessalines does @mixomat approach helps you? Can I close this issue?

@Martin-Luft
Copy link
Contributor

@dessalines look at @mixomat PR #1088 :)

@dessalines
Copy link
Author

@mixomat I think for that to work, the result objects would have to have identical fields(they don't), and be manipulated to add a custom group field name to every object.

I think this doesn't fit my use case, #1088 is more about grouping a single result set under different titles, while my use case is about multiple result sets, IE, fetching from different sources with potentially different data, and displaying them on the same typeahead box.

https://twitter.github.io/typeahead.js/examples/#multiple-datasets

@mixomat
Copy link
Contributor

mixomat commented Oct 7, 2016

@dessalines You're right, the typeahead directive expects kind of a normalized datasets, where each item is of the same model class.

Fetching from different sources and grouping by source type (the NBA/NHL team use case) is still possible with the current implementation, as both sources share the same model (US Sports Team).

If the model differs from data source to data source, it can't be displayed right now, as only a single itemTemplate reference, optionField and groupField is supported, right now.

@valorkin
Copy link
Member

it could be tricky but I will try to make it in typeahead v2

@valorkin valorkin added the WIP label Jan 19, 2017
@YevheniiaMazur YevheniiaMazur changed the title Typeahead multiple result sets feat(typeahead): add using multiple sets of results at typeahead Jan 16, 2018
@ghost
Copy link

ghost commented Jan 10, 2019

@dessalines I think multiple result sets were implemented here

@dessalines
Copy link
Author

That only works if the types are identical.... lets say I want the search field to find both users and tags, those shouldn't have the same fields,

valorkin added a commit that referenced this issue May 26, 2025
- Add TypeaheadDataset interface for configuring multiple data sources
- Add typeaheadDatasets input property to TypeaheadDirective
- Implement processMultipleDatasets method to handle multiple sources
- Support dataset-specific configuration (headers, limits, display fields)
- Maintain full backward compatibility with single typeahead input
- Add comprehensive unit tests for multiple datasets functionality
- Add E2E tests to verify multiple datasets behavior

Fixes #794

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants