Skip to content
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

Request: Children #186

Closed
jocelynduc opened this issue Jan 12, 2018 · 13 comments · Fixed by #1022
Closed

Request: Children #186

jocelynduc opened this issue Jan 12, 2018 · 13 comments · Fixed by #1022

Comments

@jocelynduc
Copy link

jocelynduc commented Jan 12, 2018

I would like to use ng-select with "children" as we can do with:
https://optimistex.github.io/ng2-select-ex/

Is this available? on the roadmap?

@varnastadeus
Copy link
Member

@jocelynduc it doesn't seem to work there. Can you describe what this feature is about?

@jocelynduc
Copy link
Author

I put a new example where the feature is actually working:
https://optimistex.github.io/ng2-select-ex/

The idea of this feature is to group options. In the example, you can see that the cities are grouped by country. Have a look at it, it speaks by itself
It should act the same as in a pure element. Only the children are effectively selectable. public items: any[] = [ { id: 100, text: 'Austria', children: [ {id: 54, text: 'Vienna'} ] }, { id: 200, text: 'Belgium', children: [ {id: 2, text: 'Antwerp'}, {id: 9, text: 'Brussels'} ] }, ... }

@varnastadeus
Copy link
Member

varnastadeus commented Jan 13, 2018

I think you can achieve similar result with custom option templates, since items are already grouped. The part that is missing, is ability to select children. I will check if there is any way to make it work for now.
Anyhow this is valid request and we will see how to better implement this so it is supported out of the box in the future.

@anjmao
Copy link
Member

anjmao commented Jan 15, 2018

@varnastadeus If you will be able to create example on demo page with items grouping and custom templates that would be great.

@carlhussey
Copy link

Any update on this? I believe it will just need to act the same as optgroup in vanilla html.

<select>
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  </optgroup>
  <optgroup label="German Cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
</select>

@ghost ghost mentioned this issue Feb 13, 2018
@anjmao anjmao self-assigned this Feb 14, 2018
@anjmao
Copy link
Member

anjmao commented Feb 14, 2018

Hi @carlhussey, I started working on this, home will implement it during this or next week.

@MadJlzz
Copy link

MadJlzz commented Mar 2, 2018

I made a simple workaround to do what you're expecting while waiting for the native feature.

<ng-select class="custom"
           [searchable]="true"
           placeholder="Select Option Type">
  <ng-template ngFor let-optionType [ngForOf]="optionTypeMock">
    <ng-option [disabled]="true" value="optionType">-- {{ optionType.category }} --</ng-option>
    <ng-option *ngFor="let style of optionType.styles" value="style">{{ style }}</ng-option>
  </ng-template>
</ng-select>

With a JSON object like this:

optionTypeMock = [
  {
    category: 'VANILLA',
    styles: [
      'EUROPEAN'
    ]
  }
];

@anjmao
Copy link
Member

anjmao commented Mar 5, 2018

I just pushed support for grouping items with groupBy https://ng-select.github.io/ng-select#/grouping Now internals are ready for children support.

@anjmao anjmao removed their assignment Mar 5, 2018
@MadJlzz
Copy link

MadJlzz commented Mar 5, 2018

@anjmao Updated your library version and already using it ! It's working like a charm, thanks !

@anjmao anjmao self-assigned this Jun 8, 2018
@anjmao anjmao mentioned this issue Jun 8, 2018
1 task
@achimha
Copy link

achimha commented Jul 14, 2018

I'm very much favor of an optgroup tag! There are situations where it's much more convenient to use markup to define the list than a data structure and benefit from the template engine in Angular.

@newprogrammer1991
Copy link

Hi, Can I make like dropdown - click by country and show citiyes ?

@newprogrammer1991
Copy link

??

@saurabh47
Copy link
Contributor

I'm also looking for ng-option-group tag.
so we can define template like. Is this tag available in this library ?

<ng-select>
  <ng-option-group label="Swedish Cars">
    <ng-option value="volvo">Volvo</ng-option>
    <ng-option value="saab">Saab</ng-option>
  </ng-option-group>
  <ng-option-group label="German Cars">
    <ng-option value="mercedes">Mercedes</ng-option>
    <ng-option value="audi">Audi</ng-option>
  </ng-option-group>
</ng-select>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants