We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid context menu. Add images and separator

Thread ID:





131704 Jul 24,2017 01:32 PM UTC Jul 27,2017 09:28 AM UTC Angular 3
Tags: ejGrid
Asked On July 24, 2017 01:32 PM UTC


I have several questions about grid context menu and submenu items:
1. How can I add images in context menu?
2. How can I add separator between items in context menu?
3. Can I use as id property number type value instead of char/string?

I am creating context menu like this, but image not showing and I am getting error when I am trying to use id as number and not as string:
<ej-grid #myGrid [contextMenuSettings]="contextMenuSettings"(contextOpen)="onContextMenuOpen($event)"></ej-grid>

private contextMenuItems: Array<any> = [];
private subContextMenuItems: Array<any> = [];

this.contextMenuItems.push({ id: '1', text: "Clear Selection", imageUrl: "/src/deps/images/menu/lightning_power_yellow_16.png" });
this.contextMenuItems.push({ id: '2', text: "Hide column" });
this.subContextMenuItems.push({ contextMenuItem: '1', subMenu: ["OrderID", "CustomerID", "EmployeeID"] });
this.subContextMenuItems.push({ contextMenuItem: '2', subMenu: ["OrderID", "CustomerID", "EmployeeID"] })

this.contextMenuSettings = { enableContextMenu: true, customContextMenuItems: this.contextMenuItems, subContextMenu: this.subContextMenuItems };

And this is how my context menu looks (no image showing and I do not know how to add separator between items):

And here is error when I am trying to use id like number (maybe it is my problem somewhere else in my code(?)):

Saravanan Arunachalam [Syncfusion]
Replied On July 25, 2017 01:26 PM UTC

Hi Agne, 
Thanks for contacting Syncfusion’s support. 
We have analyzed your requirement that we have achieved by using “create” event of Grid control. Please refer to the below code example. 
        .e-grid .e-customitem>span{ 
            top: "30%"; 
            position: absolute; 
<ej-grid #myGrid [contextMenuSettings]="contextMenuSettings"(contextOpen)="onContextMenuOpen($event)" (create)="onCreate($event)"></ej-grid> 
export class GridComponent { 
    . . . 
        //Add the separator 
        //Add icon to the items 
        $("#1").prepend("<span  class='e-icon e-cancel'></span>"); 
        $("#2").prepend("<span  class='e-icon e-save'></span>"); 
Saravanan A. 

Replied On July 26, 2017 08:10 AM UTC

Thank you, it is very helpful!

I have one more question about this - maybe there is some possibility add images not using jQuery with prepend/append, but there is some grid context menu item property like imageUrl, icon or something like that? Or maybe this will be done in the future?

Saravanan Arunachalam [Syncfusion]
Replied On July 27, 2017 09:28 AM UTC

Hi Agne, 
We have rendered the context menu based on the <ul><li> template at our source side. In <ul> <li> template, we need to manually add a <span> element with image class inside the <a> tag to display image and we cannot set it using spriteCssClass field as the datasource property which is empty for rendering using <ul> template. Kindly refer to the following playground sample: http://jsplayground.syncfusion.com/mnc4wyki  
So, we can achieved your requirement by append the <span> to add icon for the context item in the create event of ejGrid control which is like provided in the previous update. 
Saravanan A.    


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon