Search code examples
vis.js-networkvis.js

Interactive nodes in vis js network


When node is selected I want to add a icon on node and on icon click I want to give options to edit or deleted selected node. Is this possible or how to implement this in Vis js?


Solution

  • you can use the click event or nodeSelected. like this:

    network.on('click', function (properties) {    
      selection = properties.nodes
    
      if (selection > 0) {
        var node_sel = nodes.get([selection])[0];
        if(node_sel['selected']){
          alert('add you buttons');
        }
        else{
          alert('change the style here');
          node_sel['selected'] = true;
          node_sel['shape'] = 'box';
          nodes.update(node_sel);
          var msg = JSON.stringify(nodes.get([selection]))
          alert(msg);
        }
      }
    });
    

    see this plunker, instead of the alerts put your code.