Skip to content

Commit e76fd45

Browse files
added column separator option for downloaded table's csv
1 parent a739e2e commit e76fd45

File tree

7 files changed

+23
-4
lines changed

7 files changed

+23
-4
lines changed

client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class TableImplComp extends TableInitComp implements IContainer {
9797
data: (this as any).exposingValues["displayData"],
9898
filename: fileName,
9999
fileType: "csv",
100+
delimiter: this.children.toolbar.children.columnSeparator.getView(),
100101
});
101102
}
102103

client/packages/lowcoder/src/comps/comps/tableComp/tableToolbarComp.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { BoolControl } from "comps/controls/boolControl";
88
import { StringControl } from "comps/controls/codeControl";
99
import { dropdownControl } from "comps/controls/dropdownControl";
1010
import { TableToolbarStyleType } from "comps/controls/styleControlConstants";
11-
import { stateComp } from "comps/generators";
11+
import { stateComp, withDefault } from "comps/generators";
1212
import { genRandomKey } from "comps/utils/idGenerator";
1313
import { ThemeContext } from "comps/utils/themeContext";
1414
import { trans } from "i18n";
@@ -560,6 +560,7 @@ export const TableToolbarComp = (function () {
560560
// searchText: StringControl,
561561
filter: stateComp<TableFilter>({ stackType: "and", filters: [] }),
562562
position: dropdownControl(positionOptions, "below"),
563+
columnSeparator: withDefault(StringControl, ','),
563564
};
564565

565566
return new ControlNodeCompBuilder(childrenMap, (props, dispatch) => {
@@ -588,6 +589,10 @@ export const TableToolbarComp = (function () {
588589
children.showFilter.propertyView({ label: trans("table.showFilter") }),
589590
children.showRefresh.propertyView({ label: trans("table.showRefresh") }),
590591
children.showDownload.propertyView({ label: trans("table.showDownload") }),
592+
children.showDownload.getView() && children.columnSeparator.propertyView({
593+
label: trans("table.columnSeparator"),
594+
tooltip: trans("table.columnSeparatorTooltip"),
595+
}),
591596
children.columnSetting.propertyView({ label: trans("table.columnSetting") }),
592597
/* children.searchText.propertyView({
593598
label: trans("table.searchText"),

client/packages/lowcoder/src/i18n/locales/de.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,8 @@ export const de: typeof en = {
13811381
"showFilter": "Schaltfläche Filter anzeigen",
13821382
"showRefresh": "Schaltfläche \"Aktualisieren\" anzeigen",
13831383
"showDownload": "Download-Schaltfläche anzeigen",
1384+
"columnSeparator": "Spaltentrennzeichen",
1385+
"columnSeparatorTooltip": "Spaltentrennzeichen („Trennzeichen“) in der heruntergeladenen CSV-Datei. \n\nEmpfehlungen:\n- Komma (,)\n- Semikolon (;)\n- Pipe (|)\n- Tabulator (\\t)",
13841386
"columnSetting": "Schaltfläche Spalteneinstellung anzeigen",
13851387
"searchText": "Text suchen",
13861388
"searchTextTooltip": "Suche und Filterung der in der Tabelle dargestellten Daten",

client/packages/lowcoder/src/i18n/locales/en.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,8 @@ export const en = {
18361836
"showFilter": "Show Filter Button",
18371837
"showRefresh": "Show Refresh Button",
18381838
"showDownload": "Show Download Button",
1839+
"columnSeparator": "Column Separator",
1840+
"columnSeparatorTooltip": "Column Separator (\"delimiter\") in downloaded CSV file. \n\nRecommendations:\n- Comma (,)\n- Semicolon (;)\n- Pipe (|)\n- Tab (\\t)",
18391841
"columnSetting": "Show Column Setting Button",
18401842
"searchText": "Search Text",
18411843
"searchTextTooltip": "Search and Filter the Data Presented in the Table",

client/packages/lowcoder/src/i18n/locales/pt.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,8 @@ export const pt: typeof en = {
19031903
"showFilter": "Mostrar Botão de Filtro",
19041904
"showRefresh": "Mostrar Botão de Atualização",
19051905
"showDownload": "Mostrar Botão de Download",
1906+
"columnSeparator": "Separador de colunas",
1907+
"columnSeparatorTooltip": "Separador de colunas (\"delimitador\") no arquivo CSV baixado. \n\nRecomendações:\n- Vírgula (,)\n- Ponto e vírgula (;)\n- Barra vertical (|)\n- Tabulação (\\t)",
19061908
"columnSetting": "Mostrar Botão de Configuração de Coluna",
19071909
"searchText": "Texto de Busca",
19081910
"searchTextTooltip": "Pesquisar e filtrar os dados apresentados na tabela",

client/packages/lowcoder/src/i18n/locales/zh.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,8 @@ export const zh: typeof en = {
14031403
showFilter: "显示筛选按钮",
14041404
showRefresh: "显示刷新按钮",
14051405
showDownload: "显示下载按钮",
1406+
columnSeparator: "柱分离器",
1407+
columnSeparatorTooltip: "下载的 CSV 文件中的列分隔符(\“分隔符\”)。 \n\n建议:\n- 逗号 (,)\n- 分号 (;)\n- 竖线 (|)\n- 制表符 (\\t)",
14061408
columnSetting: "显示列设置按钮",
14071409
searchText: "搜索文本",
14081410
searchTextTooltip: "搜索和筛选在表格中呈现的数据",

client/packages/lowcoder/src/util/fileUtils.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ interface SaveDataAsFileParams {
3131
filename: string;
3232
fileType: "empty" | "txt" | "json" | "csv" | "xlsx" | string;
3333
dataType?: "url" | "base64";
34+
delimiter?: string;
3435
}
3536

36-
export async function saveDataAsFile({ data, filename, fileType, dataType }: SaveDataAsFileParams) {
37+
export async function saveDataAsFile({ data, filename, fileType, dataType, delimiter }: SaveDataAsFileParams) {
3738
if (dataType === "url") {
3839
return saveAs(data, filename, { autoBom: true });
3940
}
@@ -72,11 +73,15 @@ export async function saveDataAsFile({ data, filename, fileType, dataType }: Sav
7273
} else {
7374
wb = XLSX.read(data, { type: "string" });
7475
}
75-
blobData = XLSX.write(wb, {
76+
let writeOptions: any = {
7677
bookType: finalFileType,
7778
bookSST: false, // whether to generate Shared String Table? setting true will slow down the generating speed, but more compatible for lower versioned iOS devices
7879
type: "buffer",
79-
});
80+
}
81+
if (finalFileType === 'csv' && delimiter) {
82+
writeOptions['FS'] = delimiter;
83+
}
84+
blobData = XLSX.write(wb, writeOptions);
8085
break;
8186
}
8287
const blob = new Blob([blobData], {

0 commit comments

Comments
 (0)