Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render missing data for columns with format string #155

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

robertjli
Copy link
Contributor

If a column has a format string, and a row is missing data in that column, an unexpected error is shown.

table.New([]table.Column{
	table.NewColumn(columnKeyName, "Name", 13),
	table.NewColumn(columnKeyElement, "Element", 10),
	table.NewColumn(columnKeyHeight, "Height", 16).WithFormatString("%.2f m"),
}).WithRows([]table.Row{
	table.NewRow(table.RowData{
		columnKeyName:    "Pikachu",
		columnKeyElement: "Electric",
		// height is missing
	}),
	table.NewRow(table.RowData{
		columnKeyName:    "Charmander",
		columnKeyElement: "Fire",
		columnKeyHeight:  0.6,
	}),
})
┏━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃         Name┃   Element┃          Height┃
┣━━━━━━━━━━━━━╋━━━━━━━━━━╋━━━━━━━━━━━━━━━━┫
┃      Pikachu┃  Electric┃  %!f(string=) m┃
┃   Charmander┃      Fire┃          0.60 m┃
┗━━━━━━━━━━━━━┻━━━━━━━━━━┻━━━━━━━━━━━━━━━━┛

This PR fixes the bug by only setting the format string if data exists.

Copy link
Owner

@Evertras Evertras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, good catch.

@Evertras Evertras merged commit 4423af9 into Evertras:main Oct 17, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants