-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Template support for selected item in Dropdown #4497
Comments
Implemented via new selectedItem template; <p-dropdown [options]="cars" [(ngModel)]="selectedCar2" [style]="{'width':'150px'}" filter="true">
<ng-template let-item pTemplate="selectedItem">
<img src="assets/showcase/images/demo/car/{{item.label}}.png" style="width:16px;vertical-align:middle" />
<span style="vertical-align:middle">{{item.label}}</span>
</ng-template>
<ng-template let-car pTemplate="item">
<div class="ui-helper-clearfix" style="position: relative;height: 25px;">
<img src="assets/showcase/images/demo/car/{{car.label}}.png" style="width:24px;position:absolute;top:1px;left:5px"/>
<div style="font-size:14px;float:right;margin-top:4px">{{car.label}}</div>
</div>
</ng-template>
</p-dropdown> |
thank you! 👍 🥇 |
i test with the code above. |
Cannot make selectedItem template work either. |
Me neither, instead of the selectedItem template I see only the item label |
Same for me. I can't add template for selectedItem. |
Works fine for me after updating to:
|
I have updated to:
and I am having the same issue listed above. My label keeps getting set to empty and is getting the ui-dropdown-label-empty class. If it helps I am using my own object. I am not passing an object like { label: any, value: any } |
@mlangwell Only thing that I may have done in addition is deleting node modules and reinstalling everything. Could be worth a shot. |
@jzaric that did not work for me. It appears that the problem is that the selectedItem is not reflecting correctly. I have my options that is of type X, then on init I grab an option of the same type and set my selectedItem variable. However, when I make a selection from the dropdown the selectedItem is undefined. Both my options and my selectedItem are of the same type. What is wrong here? |
I also can't get selectedItem template to work. I'm using "primeng": "^5.0.2" is it safe to update to 5.2.0? My site relies a lot on p-datatable... |
@AndreMantas , p-dataTable won't be removed, it is just not maintained anymore. It stays as it is so that users can still upgrade. |
Datatables seems to be working fine. However my p-tieredMenus are broken. Did something change? Where can i see the changelog? |
@mlangwell Thank you for your input. It turns out converting it to exactly {label: string, value: any} did the trick for me. I am not sure if this is a bug or designed this way. Either way, it wasn't evident from the docs. |
I'm submitting a ...
Current behavior
You set up an
<ng-template>
for a<p-dropdown>
component, your template successfully appears on the dropdown selection menu, but not when an item is selected.Expected behavior
I'd expect that if I style an item with a template, it'd be styled both in the selection menu and when the item is selected.
(I can understand the complication of this, but maybe if I had a different approach available, for example setting a pipe chain to the label (which would ensure the label remains a text value, and not a complete "template" which can be anything).
Minimal reproduction of the problem with instructions
https://plnkr.co/edit/Le9tpxsgLsH6u8rvqjQX?p=preview
In this plunk I have both dropdowns with values 1, 10, 100, 1000, 10000, both showing different currencies, I'd like this to show when an item is selected as well, without modifying my option source if possible.
What is the motivation / use case for changing the behavior?
Everything is doable by changing the options data source, but I feel it would make it more declarative by having using the existing data source and simply defining a template which would affect both the selected item and items in the selection menu (or a separate template for the selected item)
Angular version: 5.0.2
PrimeNG version: 5.0.0
Browser: all
Language: all
The text was updated successfully, but these errors were encountered: