mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
976 B
29 lines
976 B
import { UITypes } from '../../../nocodb-sdk' |
|
import type { ColumnType } from '../../../nocodb-sdk' |
|
import type { Row } from '~/lib' |
|
|
|
export const copyTable = async (rows: Row[], cols: ColumnType[]) => { |
|
let copyHTML = '<table>' |
|
let copyPlainText = '' |
|
|
|
rows.forEach((row) => { |
|
let copyRow = '<tr>' |
|
cols.forEach((col) => { |
|
let value = (col.title && row.row[col.title]) ?? '' |
|
if (typeof value === 'object') { |
|
value = JSON.stringify(value) |
|
} |
|
copyRow += `<td>${value}</td>` |
|
copyPlainText = `${copyPlainText} ${value} \t` |
|
}) |
|
copyHTML += `${copyRow}</tr>` |
|
copyPlainText = `${copyPlainText.trim()}\n` |
|
}) |
|
copyHTML += '</table>' |
|
copyPlainText.trim() |
|
|
|
const blobHTML = new Blob([copyHTML], { type: 'text/html' }) |
|
const blobPlainText = new Blob([copyPlainText], { type: 'text/plain' }) |
|
|
|
return navigator.clipboard.write([new ClipboardItem({ [blobHTML.type]: blobHTML, [blobPlainText.type]: blobPlainText })]) |
|
}
|
|
|