JavaScript/jQuery ContextMenu - Customize Item Appearance
For a minor customization of ContextMenu items, you can define specific fields in item data objects. For example, the following code generates three context menu items. Between the first and the second items lies a separator dividing one group of items from another. All the items are supplied with icons.
HTML
TypeScript
- <dx-context-menu
- [items]="contextMenuItems"
- target="#someElement"
- [visible]="true">
- </dx-context-menu>
- import { DxContextMenuModule } from 'devextreme-angular';
- // ...
- export class AppComponent {
- contextMenuItems = [
- { text: 'Zoom In', icon: 'plus' },
- { text: 'Share', icon: 'message', beginGroup: true },
- { text: 'Download', icon: 'download' }
- ];
- }
- @NgModule({
- imports: [
- // ...
- DxContextMenuModule
- ],
- // ...
- })
If you need a more flexible solution, define an itemTemplate.
HTML
TypeScript
- <dx-context-menu
- [items]="contextMenuItems"
- target="#someElement"
- itemTemplate="item"
- [visible]="true">
- <div *dxTemplate="let data of 'item'; let i = index">
- <span class="dx-icon-{{data.icon}}"></span>
- <i style="margin-left:5px">{{data.text}}</i><span> [{{i + 1}}]</span>
- </div>
- </dx-context-menu>
- import { DxContextMenuModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- contextMenuItems = [
- { text: "Zoom In", icon: "plus" },
- { text: "Share", icon: "message" },
- { text: "Download", icon: "download" }
- ];
- }
- @NgModule({
- imports: [
- // ...
- DxContextMenuModule
- ],
- // ...
- })
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.