Skip to content

Commit b46bf51

Browse files
committed
fix: derive DataGrid2 column names from attribute or caption
Column names were always generated as sequential identifiers (col1, col2, ...) in DESCRIBE PAGE output. Now derives semantic names from the column's bound attribute or caption text, falling back to col%d only when neither is available.
1 parent 9b0635c commit b46bf51

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

mdl/executor/cmd_pages_describe_output.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,9 @@ func (e *Executor) outputWidgetMDLV3(w rawWidget, indent int) {
354354
}
355355
fmt.Fprintf(e.output, "%s }\n", prefix)
356356
}
357-
// Output columns
357+
// Output columns — derive name from attribute or caption, fall back to col%d
358358
for i, col := range w.DataGridColumns {
359-
// Generate synthetic column name since Mendix doesn't store it
360-
colName := fmt.Sprintf("col%d", i+1)
359+
colName := deriveColumnName(col, i)
361360
e.outputDataGrid2ColumnV3(prefix+" ", colName, col)
362361
}
363362
fmt.Fprintf(e.output, "%s}\n", prefix)
@@ -576,6 +575,31 @@ func (e *Executor) outputWidgetMDLV3(w rawWidget, indent int) {
576575
}
577576
}
578577

578+
// deriveColumnName produces a semantic column name from the column's attribute
579+
// or caption. Falls back to "col%d" when neither is available.
580+
func deriveColumnName(col rawDataGridColumn, index int) string {
581+
if col.Attribute != "" {
582+
// Use the short attribute name (last segment after dot)
583+
parts := strings.Split(col.Attribute, ".")
584+
return parts[len(parts)-1]
585+
}
586+
if col.Caption != "" {
587+
// Sanitize caption to a valid identifier: keep alphanumeric, replace rest with underscore
588+
sanitized := strings.Map(func(r rune) rune {
589+
if r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' || r >= '0' && r <= '9' || r == '_' {
590+
return r
591+
}
592+
return '_'
593+
}, col.Caption)
594+
// Trim leading/trailing underscores and collapse multiples
595+
result := strings.TrimFunc(sanitized, func(r rune) bool { return r == '_' })
596+
if result != "" {
597+
return result
598+
}
599+
}
600+
return fmt.Sprintf("col%d", index+1)
601+
}
602+
579603
// outputDataGrid2ColumnV3 outputs a single DataGrid2 column in V3 MDL syntax.
580604
func (e *Executor) outputDataGrid2ColumnV3(prefix, colName string, col rawDataGridColumn) {
581605
// Build the main column properties

0 commit comments

Comments
 (0)