Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
How to create context menu in mxGraph when clicked on canvas ( null cell)?

On my application using mxGraph, I have a feature that enables a context menu when it is clicked on a cell and returns different options based on where it is clicked - edge or vertex. My code looks like this:

   graph.popupMenuHandler.factoryMethod = function (menu, cell, evt) {
     if (cell.edge) {
       menu.addItem("First edge option", null, function () {
         alert("This is the first option of edge ");
       });
       menu.addItem("Second edge option", null, function () {
         alert("This is the second option of edge ");
       });
     }
     if (cell.vertex) {
       menu.addItem("View Properties", null, function () {
         document.getElementById("property-panel").style["display"] = "block";
       });
       menu.addItem("View Measurements ", null, function () {
         if (cell.measurementName!= null) {
           openPopup(cell);
         } else {
           showAlert("This component does not have any plots!");
         }
       });
     }
   };

This works great, But I want to be able to right click on the blank canvas that is not a cell, ie, somewhere on the editor, but which does not contain any vertex or edge. The problem with that is, this method, works only when a cell is clicked, as it's parameters are menu, cell, and evt. Since there is no cell on a blank canvas, it gives out this following error: Uncaught TypeError: cell is null. Does anyone know if there is a better implementation, if there is an approach where I could create an empty cell (invisible) when the user right-clicks, and then fire up the context menu by passing the invisible cell?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda