copy doubleclicked cell without using button

copy doubleclicked cell without using button

rivaldidrivaldid Posts: 55Questions: 6Answers: 2

Any chance to get it working? I don't want use buttons, I know how to do with them:
{ extend: 'selectedSingle',
text: 'Copia cella',
action: function ( e, dt, node, config ) {
var sdata = table.cell('.selected').data();
copyToClipboard(sdata);
}
}
Button usage is not so comfortable, it means an action more and not all user forget to use and everytime they try to copy the cell using mouse highlight. Now I want change it and use the dblclick event on a cell but I don't know how to make it working.
I'm trying this code but all it does is return the whole row
$( table.table().body() ).on('dblclick', 'td', function(){
var idx = table.cell('.selected',0).index();
var data = table.row(idx.row).data();
console.log(data);
//copyToClipboard(sdata);
});

Answers

  • rivaldidrivaldid Posts: 55Questions: 6Answers: 2

    I'm dumb, I solved with the most stupid way I can have thought:
    $( table.table().body() ).on('dblclick', 'td', function(){
    copyToClipboard($(this).html());
    });

    And of course copytoclipboard is a custom function:
    function copyToClipboard(string) {
    var $temp = $("<input>");
    $("body").append($temp);
    //$temp.val($(element).text()).select();
    $temp.val(string).select();
    document.execCommand("copy");
    $temp.remove();
    };

    Bye

Sign In or Register to comment.