Skip to content

Commit

Permalink
Fixed #10159 - Header and Footer Template for AutoComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitfindikli committed Apr 26, 2021
1 parent a07431b commit cef232d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/app/components/autocomplete/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const AUTOCOMPLETE_VALUE_ACCESSOR: any = {
(click)="handleDropdownClick($event)" *ngIf="dropdown" [attr.tabindex]="tabindex"></button>
<div #panel *ngIf="overlayVisible" [ngClass]="['p-autocomplete-panel p-component']" [style.max-height]="virtualScroll ? 'auto' : scrollHeight" [ngStyle]="panelStyle" [class]="panelStyleClass"
[@overlayAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}" (@overlayAnimation.start)="onOverlayAnimationStart($event)">
<ng-container *ngTemplateOutlet="headerTemplate"></ng-container>
<ul role="listbox" [attr.id]="listId" class="p-autocomplete-items" [ngClass]="{'p-autocomplete-virtualscroll': virtualScroll}">
<ng-container *ngIf="group">
<ng-template ngFor let-optgroup [ngForOf]="suggestions">
Expand Down Expand Up @@ -74,6 +75,7 @@ export const AUTOCOMPLETE_VALUE_ACCESSOR: any = {
<li *ngIf="noResults && emptyMessage" class="p-autocomplete-emptymessage p-autocomplete-item">{{emptyMessage}}</li>
</ng-template>
</ul>
<ng-container *ngTemplateOutlet="footerTemplate"></ng-container>
</div>
</span>
`,
Expand Down Expand Up @@ -227,6 +229,10 @@ export class AutoComplete implements AfterViewChecked,AfterContentInit,OnDestroy

itemTemplate: TemplateRef<any>;

headerTemplate: TemplateRef<any>;

footerTemplate: TemplateRef<any>;

selectedItemTemplate: TemplateRef<any>;

groupTemplate: TemplateRef<any>;
Expand Down Expand Up @@ -370,6 +376,14 @@ export class AutoComplete implements AfterViewChecked,AfterContentInit,OnDestroy
this.selectedItemTemplate = item.template;
break;

case 'header':
this.headerTemplate = item.template;
break;

case 'footer':
this.footerTemplate = item.template;
break;

default:
this.itemTemplate = item.template;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,14 @@ <h5>Templates</h5>
<td>selectedItem</td>
<td>$implicit: value</td>
</tr>
<tr>
<td>header</td>
<td>-</td>
</tr>
<tr>
<td>footer</td>
<td>-</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit cef232d

Please sign in to comment.