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

Automatic format of number types #29

Open
michalfita opened this issue Jun 8, 2021 · 3 comments
Open

Automatic format of number types #29

michalfita opened this issue Jun 8, 2021 · 3 comments

Comments

@michalfita
Copy link

The ConsoleTables has a nice feature, where .Configure(o => o.NumberAlignment = Alignment.Right) sets up automatic right alignment of numbers in the table.

Would you consider adding similar mechanism to your project?

@minhhungit
Copy link
Owner

hi @michalfita ,
ConsoleTableExt treat all values as string, so it does not discriminate "number" or "string"

but ConsoleTableExt also has a feature which give us define which columns we want to align using WithTextAlignment extension, for example:

.WithTextAlignment(new Dictionary<int, TextAligntment>{
    { 1, TextAligntment.Right },
    { 3, TextAligntment.Center}
})

In above example, 1 and 3 are column indexs

Same, you can align header with extension WithHeaderTextAlignment

.WithHeaderTextAlignment(new Dictionary<int, TextAligntment> {
   {1, TextAligntment.Center }
})

Check more in example project here https://github.com/minhhungit/ConsoleTableExt/tree/master/Src/ConsoleTableApp

@michalfita
Copy link
Author

I'm aware of this feature, however this require really going extra mile in comparison to ConsoleTables if you want to stick with simple From() call but want numbers right aligned. As you keep List<List<object>> some extra meta-magic would be possible figured if the original data were actually the number.

@minhhungit
Copy link
Owner

Support the feature is not too hard, but we will need to check every values in the table to verify if value is a "number" or not, this will cause a performance problem, it can be slower for large table. Anyway, I will consider to support it, I admit that defining text align by column index is quite bored

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

No branches or pull requests

2 participants