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't add a separator before last row #14

Open
ZzAntares opened this Issue Nov 8, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@ZzAntares
Copy link

ZzAntares commented Nov 8, 2016

Hi, just getting started with this lib, however I need to add a separator before the last row and I don't see how, is it possible to do it?

+------+---------+-------+----------+
| Seat | Markers | MXN   | Checkout |
+------+---------+-------+----------+
|  1   |  60     |  600  |    600   |
|  2   |  30     |  600  |   -600   |
|  3   |  10     |  300  |    300   |
|  1   |  10     |  100  |   -100   |
+------+---------+-------+----------+
|      |         | Total |   +200   |
+------+---------+-------+----------+

That final row (Total) how could I divide it from the other above it? Is it possible?

Thanks!

@djm

This comment has been minimized.

Copy link
Owner

djm commented Nov 8, 2016

@ZzAntares Sadly it doesn't support this at the moment.

horizontal_style can be one of [:off, :frame, :header, :all] but there is no :footer or :header_and_footer option yet. I'm also not totally sure there should be as there starts to become too many edge-case options and we can't possibly cover every scenario - it sounds more like it should be something that should be configurable at the row level.

We have put_column_meta to control column level meta (alignment etc). We could possibly have a put_row_meta with a :separator or :delimit boolean denoting that that row should be surrounded.

This is a substantial amount of work, I will attempt to get to it soon but I can't make any promises unless someone else would like to pick it up (and we can then better spec out what the new API would look like).

@ZzAntares

This comment has been minimized.

Copy link

ZzAntares commented Nov 8, 2016

Thanks a lot for the honest words, no worries, in the mean time I added a row with -- as values, it doesn't look as good as I wanted to but at least makes visible that division.

I'll keep an eye in the project for this to be implemented.

Thanks!

@djm

This comment has been minimized.

Copy link
Owner

djm commented Nov 9, 2016

@ZzAntares

That's one hack, another probably visually better hack is to take advantage of the fact it just returns a string and insert a new row that way. Given the example:

header = ["Artist", "Track", "Label", "Year"]
rows = [
  ["Konflict", "Cyanide", "Renegade Hardware", 1999],
  ["Marcus Intalex", "Temperance", "Soul:r", 2004],
  ["Kryptic Minds", "The Forgotten", "Defcom Records", 2007]
]
# Split the output on new lines and store the list for later.
table = TableRex.quick_render!(rows, header) |> String.split("\n")
# Take the first line as we can duplicate it and reinsert.
separator = table |> Enum.at(0)
table
# Reinsert the separator line into the table list.
|> List.insert_at(-4, separator)
# Turn the table list back into a newline-joined string.
|> Enum.join("\n")
# To display it.
|> IO.puts

Output would look like this:

+----------------+---------------+-------------------+------+
| Artist         | Track         | Label             | Year |
+----------------+---------------+-------------------+------+
| Konflict       | Cyanide       | Renegade Hardware | 1999 |
| Marcus Intalex | Temperance    | Soul:r            | 2004 |
+----------------+---------------+-------------------+------+
| Kryptic Minds  | The Forgotten | Defcom Records    | 2007 |
+----------------+---------------+-------------------+------+

Hope it helps? Wish it was a proper solution. I'm leaving this ticket open to serve as a reminder both to me when I get a chance or anyone that wants to pick it up.

@djm djm added the Kind:Enhancement label Nov 9, 2016

@ZzAntares

This comment has been minimized.

Copy link

ZzAntares commented Nov 10, 2016

Thanks @djm, I've modified my code accordingly, your suggestion looks just the way I wanted.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment