Context Menu for Specific Cells of Grid

1 Answer 135 Views
Grid Menu
Charlie
Top achievements
Rank 2
Charlie asked on 07 Nov 2023, 08:38 PM
I've seen some examples for displaying a context menu and retrieving the data item of the row that was clicked, but is there a way to also determine which column of the grid was clicked when the context menu is displayed?

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 10 Nov 2023, 01:56 PM

Hello Charlie,

Thank you for the details provided.

In order to achieve the desired result, I would recommend using the following approach:

  1. Set the filter of the ContextMenu to "td".
  2. In the "Select" Event handler of the ContextMenu, get the instance of the Grid.
  3. Get the current cell by using the "e.target"(use the 0 index as this will return a collection).
  4. Use the cell in order to find its index.
  5. Get the header name of the Grid by using the index of the current cell.
  6. Here is an example of the Select Event handler:
              var grid = $("#grid").data("kendoGrid");
              
              var currCell = $(e.target)[0];
              var currCellIndex = $(currCell).index();
        
              var columnHeader= grid.options.columns[currCellIndex];
              
              console.log(columnHeader);

Here is a dojo example of the approach above:

I hope this achieves the desired result.

Kind Regards,
Anton Mironov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.

Tags
Grid Menu
Asked by
Charlie
Top achievements
Rank 2
Answers by
Anton Mironov
Telerik team
Share this question
or