question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plugin Development: How to set custom attributes to a cell

See original GitHub issue

How can I set a custom attribute for a cell that gets saved with the document? getAttribute/setAttribute does not work the way I think.

I found this documentation, but it does not really help. I don’t understand how I can use an XML node as the value of the cell.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
hedietcommented, May 25, 2020

For future reference:

This code is completely neutral to how draw.io edits and displays labels.

function getLinkedData(cell) {
    if (!mxUtils.isNode(cell.value)) {
        return undefined;
    }
    return cell.value.getAttribute("hedietLinkedData");
}

function setLinkedData(cell, linkedData) {
    let newNode;
    if (!mxUtils.isNode(cell.value)) {
        var doc = mxUtils.createXmlDocument();
        var obj = doc.createElement("object");
        obj.setAttribute("label", cell.value || "");
        newNode = obj;
    } else {
        newNode = cell.value.cloneNode(true);
    }
    newNode.setAttribute("hedietLinkedData", linkedData);
    cell.setValue(newNode);
}

Documents with nodes that have been associated with data like this can be edited on draw.io without the need for plugins. Providing a custom convertValueToString is not necessary.

0reactions
chengkehancommented, Sep 2, 2022

@hediet Many many thanks. I’ve been searched a way for a long time, and your solution a perfect. Hope there will be a complete api document for plugin developers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to call the value of a plugin custom attributes from javascript
hello, i would like to get the value af a plugin custom attributes in javascript, but i don't know the way. best regards...
Read more >
Extend Gutenberg Blocks with Custom Attributes and Controls
Create custom Gutenberg block attributes & control using these available filters: blocks.registerBlockType, editor.BlockEdit & blocks.
Read more >
Adding Custom Attributes | WordPress.org
I have the plugin installed and working. However, adding new custom attribute values I am having issues with. I can add the new...
Read more >
How to add custom attributes to each timeslot cell in ...
I am building this Scheduler plugin on top of an existing backend system. One of the backend javascript detect clicks on elements with...
Read more >
Custom Attributes Plugin - Mattermost
Plugin that allows you to add custom attributes to users in Mattermost.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found