Note that there are some explanatory texts on larger screens.

plurals
  1. POTrigger cell copy (Ctrl+c) programatically with SlickGrid
    primarykey
    data
    text
    <p>I am using the <code>copy/paste</code> feature implemented in <code>Slickgrid</code>'s <code>slick.cellcopymanager.js</code> which is working fine (i.e. if you select some cells and press <code>Ctrl+c</code> then the content of these cells will be copied into your clipboard).</p> <p>I would like to trigger the <code>Ctrl+c</code> action programatically (for instance to allow doing copy/paste by clicking buttons instead of pressing keys). I know how to define the keydown event for <code>Ctrl+c</code>:</p> <pre><code>var e = jQuery.Event("keydown"); e.which = 67; e.ctrlKey = true; </code></pre> <p>however I just can't find out which object to trigger that event with and how so as to simulate the manual <code>Ctrl+c</code>. First I tried a simple trigger of the event which didn't work: </p> <p>-<code>div_dom_from_selected_cell.trigger(e); // nothing happens</code><br> -<code>grid_dom_wrapper.trigger(e); // nothing happens</code><br> -<code>$('body').trigger(e); // nothing happens</code><br> -<code>my_grid.trigger(e); // trigger is not a function</code></p> <p>Then I extended <code>slick.cellcopymanager.js</code> so as to make the <code>handleKeyDown</code> function available externally:</p> <pre><code>$.extend(this, { "init": init, "destroy": destroy, "clearCopySelection": clearCopySelection, "handleKeyDown": handleKeyDown, // ADDED THIS LINE "onCopyCells": new Slick.Event(), "onCopyCancelled": new Slick.Event(), "onPasteCells": new Slick.Event() }); </code></pre> <p>And tried to use it:</p> <pre><code>var copyManager = new Slick.CellCopyManager(); copyManager.init(my_grid); copyManager.handleKeyDown(e, { cell: cell, row: row, grid: my_grid } ); </code></pre> <p>The copying of the cell still doesn't work despite:<br> -me having a cell properly selected (it has the <code>selected</code> class)<br> -<code>handleKeyDown</code> being fired properly<br> -<code>e</code> and <code>args</code> arguments inside <code>handleKeyDown</code> looking good (I'm tracing with <code>console.log</code> and can't see any difference between manual <code>Ctrl+c</code> and programatic attempt` </p> <p><strong>How can I trigger the <code>Ctrl+c</code> event so as to copy a cell programatically?</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload