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

dynamically set the label of a table column #1431

Open
emicklei opened this issue Jan 10, 2025 · 1 comment
Open

dynamically set the label of a table column #1431

emicklei opened this issue Jan 10, 2025 · 1 comment
Assignees
Labels
approved This feature request will be implemented enhancement A new feature request
Milestone

Comments

@emicklei
Copy link

Describe the feature

i want to build multi-language support in my application.
Table is one of the widgets that uses the "label" tag of a struct field in the collection element type, which now is a constant.
The idea is to have an optional function that can do the lookup ; in the example below it is called "SetLabelFunc"

Relevant code

type language struct {
		Name   string `label:"lang_name"`
		Rating int    `display:"-"`
	}
	tab := core.NewTable(b)
	tab.SetLabelFunc(func(columnIndex int, fieldName, labelTag string) string {
		// do translation lookup here, might want to use fallback labelTag or fieldName
		return "Name"
	})
	tab.SetSlice(&[]language{{"Go", 10}, {"Python", 5}})
@emicklei emicklei added the enhancement A new feature request label Jan 10, 2025
@kkoreilly
Copy link
Member

@emicklei Thank you for suggesting this. I will add support for something similar to this when I have the time; it makes sense to have a generic function that gives you the actual header button and allows you set the text, icon, tooltip, etc to whatever you want. I will likely make that an interface similar to the one I will add in #1204, and I will make one for forms as well. I will probably work on this in conjunction with #1204 when I have the time.

Please also note that we will add built-in support for multiple languages in #9, but this is useful functionality regardless.

@kkoreilly kkoreilly self-assigned this Jan 11, 2025
@kkoreilly kkoreilly added the approved This feature request will be implemented label Jan 11, 2025
@kkoreilly kkoreilly added this to the v0.4 milestone Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved This feature request will be implemented enhancement A new feature request
Projects
Status: Todo
Development

No branches or pull requests

2 participants