DataGrid Row Templates

I'm trying to implement a "copy to clipboard" feature with the selected rows in the DataGrid. Is there any way to get the HTML element of a specific item?

I would assume there is some way to get the render fragment of an item and maybe that would have the HTML in it, but I haven't had any luck so far.


Hi @beeterry,

At the moment there isn't any built-in way to get the HTML of a specific item. You will need to use JS interop for that. For example you can assign id attribute to every DataGrid row via the RowRender event (check our demo).

    void RowRender(RowRenderEventArgs<OrderDetail> args)
        // Use the actual data item (e.g. OrderDetail instance) to generate the id attribute of the row.
        // It must be globally unique.
        args.Attributes.Add("id", GenerateUniqueID(args.Data);

Then use JS to get the element by id and obtain its innerHTML.

function getHTML(id) {
    var element = document.getElementById(id);
    return element.innerHTML;
1 Like