How can I dynamically add url to a cell, via contextMenu?

Tags: #<Tag:0x00007efc6232a928>

I have a table with ContextMenu. 12345.
I wanna add url to current cell. But i can’t do it.
I think because I am transferring the wrong instance. How can i do it? Help me please :frowning:

I tried to do so :

 callback(key, selection, clickEvent) {
          const td = this.getCell(selection[0].start.row, selection[0].end.col);
          const instance = this.getCellMeta(selection[0].start.row, selection[0].end.col).instance;
          const prop = this.getCellMeta(selection[0].start.row, selection[0].end.col).prop;

          Handsontable.renderers.TextRenderer.apply(that,
            [
              instance,
              td,
              selection[0].start.row,
              selection[0].end.col,
              prop,
              this.getValue(),
              this.getCellMeta(selection[0].start.row, selection[0].end.col)
            ]);

          if ([...td.childNodes][0]?.nodeName !== "A") {
            const link = prompt('Enter link');
            const linkValue = `<a href="${link}" target="_BLANK">${this.getValue()}</a>`;
            td.style.textDecoration = 'underline';
            Handsontable.renderers.HtmlRenderer.apply(that,
              [
                instance,
                td,
                selection[0].start.row,
                selection[0].end.col,
                prop,
                linkValue,
                this.getCellMeta(selection[0].start.row, selection[0].end.col)
              ]);
          }
        },

but I can’t rerender main table.

Hey @mixa060889

do you get any errors in the console after the user clicks that option in the menu?
Here https://jsfiddle.net/045xtvzd/2/ I have made an example that can help you. It uses the HtmlRenderer to attach a link to a cell based on its selection.

1 Like

Nope. It doesn’t output anything to the console. and does not update.
Thnx, This is the behavior that I wanted to achieve

Great. I’m happy that my demo helped.

Please feel free to open a new topic on the forum or mail me at support@handsontable.com if you’d need anything else.