mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
Add Copy With Headers to grid cell popup. (#1208)
* Add "Copy with headers" to grid cell popup. This is what you want when you're going to paste into e.g. an email. Tested just by manually trying copy and paste into an editor and an email, and then again using the new variant to confirm the headers show up. https://github.com/gristlabs/grist-core/pull/1208
This commit is contained in:
@@ -30,12 +30,16 @@ export function fieldInsertPositions(viewFields: KoArray<ViewFieldRec>, index: n
|
||||
* @param {CopySelection} selection - a CopySelection instance
|
||||
* @return {String}
|
||||
**/
|
||||
export function makePasteText(tableData: TableData, selection: CopySelection) {
|
||||
export function makePasteText(tableData: TableData, selection: CopySelection, includeColHeaders: boolean) {
|
||||
// tsvEncode expects data as a 2-d array with each a array representing a row
|
||||
// i.e. [["1-1", "1-2", "1-3"],["2-1", "2-2", "2-3"]]
|
||||
const values = selection.rowIds.map(rowId =>
|
||||
selection.columns.map(col => col.fmtGetter(rowId)));
|
||||
return tsvEncode(values);
|
||||
const result = [];
|
||||
if (includeColHeaders) {
|
||||
result.push(selection.fields.map(f => f.label()));
|
||||
}
|
||||
result.push(...selection.rowIds.map(rowId =>
|
||||
selection.columns.map(col => col.fmtGetter(rowId))));
|
||||
return tsvEncode(result);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +74,7 @@ export function makePasteHtml(tableData: TableData, selection: CopySelection, in
|
||||
)),
|
||||
// Include column headers if requested.
|
||||
(includeColHeaders ?
|
||||
dom('tr', selection.colIds.map(colId => dom('th', colId))) :
|
||||
dom('tr', selection.fields.map(field => dom('th', field.label()))) :
|
||||
null
|
||||
),
|
||||
// Fill with table cells.
|
||||
|
||||
Reference in New Issue
Block a user