Skip to content
This repository was archived by the owner on Dec 2, 2023. It is now read-only.

Commit 30ff2c9

Browse files
committed
fix field sort in excel submission export
1 parent 23e67c8 commit 30ff2c9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Template for next version
2626

2727
### Fixed
2828

29+
- field sort in excel submission export (https://github.com/ohmyform/ohmyform/issues/163)
30+
2931
### Security
3032

3133
## [1.0.1] - 2022-03-01

components/form/admin/export.submission.action.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export const ExportSubmissionAction: React.FC<Props> = (props) => {
3636
workbook.created = new Date()
3737
workbook.modified = new Date()
3838

39+
const orderedFields = form.data.form.fields
40+
.sort((a, b) => (a.idx ?? 0) - (b.idx ?? 0))
41+
3942
const sheet = workbook.addWorksheet('Submissions')
4043
sheet.getRow(1).values = [
4144
'Submission ID',
@@ -45,7 +48,7 @@ export const ExportSubmissionAction: React.FC<Props> = (props) => {
4548
'City',
4649
'User Agent',
4750
'Device',
48-
...form.data.form.fields.map((field) => `${field.title} (${field.type})`),
51+
...orderedFields.map((field) => `${field.title} (${field.type})`),
4952
]
5053

5154
const firstPage = await getSubmissions({
@@ -65,7 +68,9 @@ export const ExportSubmissionAction: React.FC<Props> = (props) => {
6568
data.device.name,
6669
]
6770

68-
data.fields.forEach((field) => {
71+
orderedFields.forEach((formField) => {
72+
const field = data.fields.find(field => field.id === formField.id)
73+
6974
try {
7075
fieldTypes[field.type]?.stringifyValue(field.value)
7176

0 commit comments

Comments
 (0)