Angular Lookup - Customize Item Appearance
For a minor customization of Lookup items, you can define specific fields in item data objects. For example, the following code generates three items: the first is not customized, the second is disabled and the third is hidden.
HTML
TypeScript
- <dx-lookup
- [dataSource]="lookupDataSource"
- valueExpr="text"
- displayExpr="text">
- </dx-lookup>
- import { DxLookupModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- lookupDataSource = [
- { text: "HD Video Player" },
- { text: "SuperHD Video Player", disabled: true },
- { text: "SuperPlasma 50", visible: false }
- ];
- }
- @NgModule({
- imports: [
- // ...
- DxLookupModule
- ],
- // ...
- })
If you need a more flexible solution, define an itemTemplate.
HTML
TypeScript
- <dx-lookup
- [dataSource]="lookupDataSource"
- valueExpr="id"
- itemTemplate="lookupItem">
- <div *dxTemplate="let item of 'lookupItem'; let i = index">
- <img src="{{item.imgSrc}}"/>
- <div
- style="display:inline-block"
- [style.font-style]="i % 2 == 0 ? 'italic' : 'normal'">
- {{item.name}}
- </div>
- </div>
- </dx-lookup>
- import { DxLookupModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- lookupDataSource = [{
- id: 1,
- name: "HD Video Player",
- imgSrc: "images/products/1-small.png"
- }, {
- id: 2,
- name: "UltraHD Player",
- imgSrc: "images/products/2-small.png"
- },
- // ...
- ];
- }
- @NgModule({
- imports: [
- // ...
- DxLookupModule
- ],
- // ...
- })
Using similar techniques, you can customize the input field of the Lookup. The template for it should be assigned to the fieldTemplate property.
HTML
TypeScript
- <dx-lookup
- [dataSource]="lookupDataSource"
- valueExpr="id"
- displayExpr="name"
- fieldTemplate="inputField">
- <div *dxTemplate="let item of 'inputField'">
- <img src="{{item.imgSrc}}" />
- </div>
- </dx-lookup>
- import { DxLookupModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- lookupDataSource = [{
- id: 1,
- name: "HD Video Player",
- imgSrc: "images/products/1-small.png"
- }, {
- id: 2,
- name: "UltraHD Player",
- imgSrc: "images/products/2-small.png"
- },
- // ...
- ];
- }
- @NgModule({
- imports: [
- // ...
- DxLookupModule
- ],
- // ...
- })
See Also
Feel free to share topic-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.