aligning cell contents (left, right, center, top, botton...)
See original GitHub issueHi,
I created a dynamic table and the header-labels are wider than the individual contents of the rows. (see attachment) I am able to format the values based on python ‘format coding’ but I seem not to be able to ‘right-align’ the values with this coding. He seems to ignore ‘>’ or not supported with flask_table at all?
value assignment to flask_table variable:
list[entry.name] = '{:>,.2f}'.format(value).replace(",", "X").replace(".", ",").replace("X", ".")
Is there a way to specify the position (left, right, center, top, bottom) of the values in the cells?
regards Michael
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Align text left or right, center text, or justify text on a page
Align the edges of your to the left, center, right, or justified, or vertically to the top, center, or bottom between margins.
Read more >Excel XP: Text and Cell Alignments - GCF Global
To align text or numbers in a cell: · Select a cell or range of cells. · Click either the Left-Align, Center, or...
Read more >vertical-align - CSS: Cascading Style Sheets - MDN Web Docs
Aligns the top padding edge of the cell with the top of the row. middle. Centers the padding box of the cell within...
Read more >(Legacy) HTML: Tables: Alignment Within a Table
It is possible to change the horizontal alignment of items within table cells. Table data defaults to left alignment; table headers to center....
Read more >Excel Text: Horizontal and vertical alignment - YouTube
Find more excel tips http://www.excel-aid.comIn this learning module"EXCEL TEXT ", you will discover how to align cell contents horizontally ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I (approximately) copied your HTML and CSS and the alignment worked as I’d expect. See here: https://jsfiddle.net/0xz68594
So I think that you’ve got some other CSS happening. Based on the
<table class="table table-striped ...">
I think you’re using Bootstrap.Bootstrap does some funny things with vertical alignment (TIL!) see here: https://getbootstrap.com/docs/4.0/utilities/vertical-align/ (make sure you look at the docs for the right version, btw).
So I added this to my bit of testing code, and vertical align stopped working. When I added the special bootstrap
align-top
class, vertical alignment worked again - see https://jsfiddle.net/3y7ceh4j/1/Hope that’s helpful!
Hi Michael! Really glad you’re using flask-table, hope I can help you.
Using Python’s formatting and the
>
and<
operators adds whitespace to a string, which will the be ignored when the browser renders the HTML which is why that isn’t working. To tackle the alignment you would need to turn to CSS instead, and you can add classes to the columns in your table using thecolumn_html_attrs
keyword (andth_html_attrs
andtd_html_attrs
).For example (you should be able to run this file and experiment):
Would generate HTML (for the table) like:
with the CSS adjusting the alignment for the elements with the classes.
There’s another example about using these keyword arguments to put attributes on the
<th>
s and the<td>
s here: https://github.com/plumdog/flask_table/blob/master/examples/column_html_attrs.pyHope some of that is helpful, let me know if you have any other questions.