nhn / tui.grid

🍞🔡 The Powerful Component to Display and Edit Data. Experience the Ultimate Data Transformer!
http://ui.toast.com/tui-grid/
MIT License
2.42k stars 394 forks source link

copy to clipboard with column name #1787

Closed ghdalsrl326 closed 1 year ago

ghdalsrl326 commented 2 years ago

Summary 아래의 이슈와 동일한 질문입니다. https://github.com/nhn/tui.grid/issues/191

혹시 기능 개발이 되었나요?

Version 4.21.1

stale[bot] commented 1 year ago

This issue has been automatically marked as inactive because there hasn’t been much going on it lately. It is going to be closed after 7 days. Thanks!

stale[bot] commented 1 year ago

This issue will be closed due to inactivity. Thanks for your contribution!

ghdalsrl326 commented 1 year ago

코드가 깔끔하진 않은데, 비슷한 기능 원하시는 분들이 있을까봐 남겨둡니다. 아래처럼 contextmenu action 정의해서 쓰시면 됩니다.

        {
          name: 'copyColumns', // copy columns
          label: 'CopyColumns',
          action: () => {
            grid.instance.setSelectionRange({
              start: [
                0,
                grid.instance.getSelectionRange()?.start[1] ??
                  grid.instance.getIndexOfColumn(grid.instance.getFocusedCell().columnName),
              ],
              end: [
                grid.instance.getRowCount(),
                grid.instance.getSelectionRange()?.end[1] ??
                  grid.instance.getIndexOfColumn(grid.instance.getFocusedCell().columnName),
              ],
            });
            grid.instance.copyToClipboard();
            const headers = grid.instance
              .getColumns()
              .filter(
                (column: OptColumn, colIdx: number) =>
                  colIdx >= grid.instance.getSelectionRange().start[1] &&
                  colIdx <= grid.instance.getSelectionRange().end[1]
              )
              .map((header: { name: string }) => header.name)
              .join('\t');
            const gridClipBoard = grid.instance.el.querySelector('.tui-grid-clipboard').innerHTML;
            navigator.clipboard.writeText(`${headers}\n${gridClipBoard}`);
          },
        },