nadbm / react-datasheet

Excel-like data grid (table) component for React
https://nadbm.github.io/react-datasheet/
MIT License
5.39k stars 457 forks source link

issue: Return value of handleCopy prop does not get copied to clipboard #268

Open damnitrahul opened 3 years ago

damnitrahul commented 3 years ago

Hi,

The return value of handleCopy prop does not get copied to the clipboard.

The docs mention that

function ({ event, dataRenderer, valueRenderer, data, start, end, range }) If set, this function is called whenever the user copies cells. The return string of this function is stored on the clipboard.

but the return value does not get copied automatically.

I looked through the code and found that the copy method is never being called for the return value of the handleCopy prop.

if (this.props.handleCopy) {
            this.props.handleCopy({
              event: e,
              dataRenderer: dataRenderer,
              valueRenderer: valueRenderer,
              data: data,
              start: start,
              end: end,
              range: range,
            });                                 <== The return value is not being copied anywhere. 
          } else {
            var text = range(start.i, end.i)
              .map(function (i) {
                return range(start.j, end.j)
                  .map(function (j) {
                    var cell = data[i][j];
                    var value = dataRenderer ? dataRenderer(cell, i, j) : null;
                    if (
                      value === '' ||
                      value === null ||
                      typeof value === 'undefined'
                    ) {
                      return valueRenderer(cell, i, j);
                    }
                    return value;
                  })
                  .join('\t');
              })
              .join('\n');
            if (window.clipboardData && window.clipboardData.setData) {
              window.clipboardData.setData('Text', text);
            } else {
              e.clipboardData.setData('text/plain', text);
            }
          }
nadbm commented 3 years ago

Sorry this is a problem in the docs rather than the actual method itself. HandleCopy is meant to override any of the default calls.