jgraph / mxgraph

mxGraph is a fully client side JavaScript diagramming library
Other
6.79k stars 2.06k forks source link

get cells by ID #483

Closed 0xbs0d closed 4 years ago

0xbs0d commented 4 years ago

Hi,

this seems like a trivial question that should have been answered somehow but I can't seem to find a normal/working answer. I want to select a bunch of cells by their ID. What I'm trying to achieve is this: when i doubleclick a cell I want to change the label of one cell and the image of another cell. While this works perfectly for the cell I'm actually clicking on I can't seem to get it to work on other cells.

editor.graph.addListener(mxEvent.DOUBLE_CLICK, function(sender, evt)
{
    // this gets me the cell I'm clicking on and using cell.id I can get it's id (for example '5') which is great
    var cell = evt.getProperty('cell');
    // I'm trying to achieve something like this where I can get another cell (for example '101')
    someid = '101';
    var cell2 = mxGraph.prototype.getCell(someid);

    // this changes the image of the cell I'm clicking on but I need to change cell2
    editor.graph.setCellStyles(mxConstants.STYLE_IMAGE, 'images/symbols/cb_open_green.png', [cell]);
}

Maybe I'm looking at it the wrong way and if so I'd like some input. Thank you

0xbs0d commented 4 years ago

Figured it out. In my case it was as easy as doing

var cell2 = editor.graph.getModel().getCell(key);