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

Can span columns be implemented? #8

Open
sibiarunachalam opened this issue Aug 5, 2022 · 4 comments
Open

Can span columns be implemented? #8

sibiarunachalam opened this issue Aug 5, 2022 · 4 comments

Comments

@sibiarunachalam
Copy link

It works well for most of my requirements.
Is it possible to implement span columns using this library?

@freva
Copy link
Owner

freva commented Aug 5, 2022

It's not currently possible. Do you want to span header/footer columns only or also some body columns?

@sibiarunachalam
Copy link
Author

Hi @freva, thanks for your feedback.
Both header and body columns require span column feature.

@freva
Copy link
Owner

freva commented Aug 8, 2022

I guess this is possible, but it's not trivial. This library takes in column definition and data separately, there is no way to control a single cell, so if this were implemented, you'd have to pass some sort of Function<T, Integer> to ColumnData which would return number of column spans for a given element, e.g.

List<Planet> planets = Arrays.asList(
        new Planet(1, "Mercury", 0.382, 0.06, "minimal"),
        new Planet(2, "Venus", 0.949, 0.82, "Carbon dioxide, Nitrogen"),
        new Planet(3, "Earth", 1.0, 1.0, "Nitrogen, Oxygen, Argon"),
        new Planet(4, "Mars", 0.532, 0.11, "Carbon dioxide, Nitrogen, Argon"));

System.out.println(AsciiTable.getTable(planets, Arrays.asList(
        new Column().with(planet -> Integer.toString(planet.num)),
        new Column().header("Name").with(planet -> planet.name).span(planet -> planet.name.equals("Earth") ? 3 : 1),
        new Column().header("Diameter").with(planet -> String.format("%.03f", planet.diameter)),
        new Column().header("Mass").with(planet -> String.format("%.02f", planet.mass)));

@sibiarunachalam
Copy link
Author

Thanks @freva for your feedback, I will look at at.

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