3

I'm trying to copy the text contents of a cell - I don't need to be able to paste into Excel or anything, I just want the plaintext content. Highlighting text, right clicking, and selecting copy works as expected (so not the same problem as in SlickGrid and Text Selection since I can select text) but highlighting and pressing ctrl+c does not (nothing gets copied to the clipboard).

I tried commenting out the keypress-handling code in slick.grid.js ($canvas.on("keydown", handleKeyDown) and $focusSink.add($focusSink2).on("keydown"), handleKeyDown)) but no change.

Chrome 61 on Windows 10, if it matters.

Reproduce with the Basic use with configuration example, with enableTextSelectionOnCells set to true:

<!DOCTYPE HTML>
<html>
    <head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <link rel="shortcut icon" type="image/ico" href="favicon.ico" />
  <title>SlickGrid example 1: Basic grid</title>
  <link rel="stylesheet" href="../slick.grid.css" type="text/css"/>
  <link rel="stylesheet" href="../css/smoothness/jquery-ui-1.11.3.custom.css"     type="text/css"/>
<link rel="stylesheet" href="examples.css" type="text/css"/>
</head>
<body>
<div id="myGrid" style="width:600px;height:500px;"></div>    
<script src="../lib/jquery-1.11.2.min.js"></script>
<script src="../lib/jquery.event.drag-2.3.0.js"></script>

<script src="../slick.core.js"></script>
<script src="../slick.grid.js"></script>

<script>
  var grid;
  var columns = [
    {id: "title", name: "Title", field: "title"},
    {id: "duration", name: "Duration", field: "duration"},
    {id: "%", name: "% Complete", field: "percentComplete"},
    {id: "start", name: "Start", field: "start"},
    {id: "finish", name: "Finish", field: "finish"},
    {id: "effort-driven", name: "Effort Driven", field: "effortDriven"}
  ];

  var options = {
    enableCellNavigation: true,
    enableTextSelectionOnCells: true,
    enableColumnReorder: false
  };

  $(function () {
    var data = [];
    for (var i = 0; i < 500; i++) {
      data[i] = {
        title: "Task " + i,
        duration: "5 days",
        percentComplete: Math.round(Math.random() * 100),
        start: "01/01/2009",
        finish: "01/05/2009",
        effortDriven: (i % 5 == 0)
      };
    }

    grid = new Slick.Grid("#myGrid", data, columns, options);
  })
</script>
</body>
</html>
alex
  • 33
  • 6
  • 2
    Possible duplicate of [SlickGrid and Text Selection](https://stackoverflow.com/questions/9966390/slickgrid-and-text-selection) – kayess Nov 17 '17 at 15:23
  • Not a duplicate - `enableTextSelectionOnCells` is true and I can select cell text. My problem is that after selecting text, ctrl+c doesn't copy anything. – alex Nov 17 '17 at 15:35
  • 1
    How could we know? [edit] your question to contain a [mcve] – kayess Nov 17 '17 at 15:36
  • Been trying to get the time to look into this. There are a couple of examples that have Excel-style cut and paste. In those, it is necessary to have an editor defined on the column, even if the column is not editable, so that it can handle conversion to and from text for the cut and paste. So this may be the same. I'll get a chance soon to review the code base. – Ben McIntyre Dec 15 '17 at 15:35
  • 1
    OK, finally got a chance to look. However, when I test the example above, selecting the text, hitting ctrl-C and pasting into Notepad works fine. Not sure what's going on. Chrome 66 on Windows 10. – Ben McIntyre Apr 23 '18 at 00:36

1 Answers1

0

I was able to get Copy to Clipboard to work using this example: https://6pac.github.io/SlickGrid/examples/example-excel-compatible-spreadsheet.html

I don't care for paste or much of the other Excel functionality, so I set readOnlyMode on like this:

grid.registerPlugin(new Slick.CellExternalCopyManager({
    readOnlyMode : true,
    includeHeaderWhenCopying : false,
}));
Andrew
  • 2,368
  • 1
  • 23
  • 30