DevExtreme React - Access the Clicked Item
To access the clicked item, handle the itemClick event. If the event handling function is not going to be changed during the lifetime of the widget, assign it to the onItemClick option when you configure the widget.
jQuery
JavaScript
$(function () { $("#contextMenuContainer").dxContextMenu({ // ... onItemClick: function (e) { var itemData = e.itemData; var itemElement = e.itemElement; var itemIndex = e.itemIndex; // ... } }); });
Angular
HTML
TypeScript
<dx-context-menu ... (onItemClick)="handleItemClickEvent($event)"> </dx-context-menu>
import { DxContextMenuModule } from "devextreme-angular"; // ... export class AppComponent { // ... handleItemClickEvent (e) { let itemData = e.itemData; let itemElement = e.itemElement; let itemIndex = e.itemIndex; // ... } } @NgModule({ imports: [ // ... DxContextMenuModule ], // ... })
If you are going to change event handlers at runtime, or if you need to attach several handlers to the itemClick event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.
JavaScript
var itemClickHandler1 = function (e) { // First handler of the "itemClick" event }; var itemClickHandler1 = function (e) { // Second handler of the "itemClick" event }; $("#contextMenuContainer").dxContextMenu("instance") .on("itemClick", itemClickHandler1) .on("itemClick", itemClickHandler2);
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.