I am looking for a way to resize a tables contents using CSS to make sure the contents all show up when printing but yet still keep the text from wrapping for any individual cell. In this example,
<table class="datatables" id="table1">
<tr>
<td style="white-space:nowrap;">This is a table with a bunch of data that stretches off the page when printed.</td>
<td style="white-space:nowrap;">I want it to print on one line, not wrap but also be sized small enough to fit on a printed page.</td>
<td style="white-space:nowrap;">It currently cuts off most of this last column.</td>
</tr>
</table>
The last td is mostly cut off when printing but all these display as I intended on one line. For example purposes I put the style inline but would be using style sheets. My ideal solution would automatically resize the font to fit still on one line per row without wrapping. Any thoughts would be appreciated.
Controlling the output of printing is a nearly impossible task. You never know the variables of what printer the user is using, what fonts are available, what settings are set, etc.
I've had this issue before, and the most clean solution for the user was to convert the table to a .pdf, which will render nearly identical across machines and printers. While it may not seem so easy to do from a technical standpoint, there is a pretty straightforward solution: datatables.
Using the "table tools" plugin, you can create a .pdf formatted version of any table with just a few lines of code and the addition of a few extra files. Here's a working demo In a nutshell, provided your table is correctly formatted and not insanely large (make sure to use <thead> tags) then you should just be able to upload the required files, apply the demo code with a change in the selector to match your table, reference the swf file that facilitates creation of the .pdf, and it should work smoothly. Most issues I've seen in setup have to do with incorrect reference to the swf path.
Voila, printable, simple code.
Maybe you can try with
#media print
{
table.datatables {font-size:10px} /*Type the value that you want*/
}
You can check a print settings in your Chrome Browser by using "Find the Scale Fields" in "Print Options" and adjust the page size on your requirements.
This is not a full-proof solution, you need to check it which values will works for you.
Use CSS transform scale property.
In my case my table width was more hence I did this using javascript.
Since my width was too much, I scaled it lower and adjusted the margin and after javascriptwindow.print() I bring it back to the original state.
document.getElementById('your table id').style.transform = ("scale(0.8)");
document.getElementById('your table id').style.margin = ("0 0 0 -15%");
You can also do it using same property in CSS.
#table {
transform: scale(0.8); //Adjust this accrding to your need by printing
margin : 0 0 0 -15%; //Adjust this accrding to your need by printing
}
Related
I have a table, this table gets data from a server, and has a few fields,
The data from the server is plain text, but no limit on how many characters.
The table should not be over 900px wide.
View example
As you can see in my plunker some texts gets very long, so they take several rows, while some fit on the first row.
In my opinion, this is not readable at all, it's horrific.
And here's the real problem, since this should be printed some time, all text must be visible.
I have tried fooling around with some fixed tables and overflow: hidden properties, though this does make the table more attractive, a lot of text would be litterly unreadable
Basically what I am asking is if there are any tried methods for displaying (maybe) a lof of texts in tables, and have it readable?
Edit: Okey, as it seems this is the way to do it, there can be some stylig done, but nothing major. There's is one thing that bothers me though, and that's that the title field (field1) is pushed to the left so much.
I know I can set width, but that requires the table to be fixed, and that will cause problems, I need the table to be as dynamic as possible.
Is it possible to set priortiy on which cells the table will break words on first? So that maybe field 1 and 5 have a low priority, so those cells will be less likely to have line breaks?
The ideal solution, and the solution I have used in most of the projects i've done is to add a modal.
For example, if you have a pragraph of texts, the best thing to do it to display a few words and then add a View more button which will open up a modal which will display the entire paragraph.
You can also try to add a View button in the end of each row in another column. Clicking this would open a modal which shows all the data in that row entirely.
This way you can show some information in the table without making it ugly and also provide all the details in the table itself(although its not present in the table view).
It looks fine to me as well, although you may try alternating row colors... add the following rule to your css... you can of course change the color to whatever you like. I find it improves readability:
tbody tr:nth-child(odd) {
background: #eee;
}
I came across a strange one today, which actually wasted a lot of my time, as I first thought it was some module that I upgraded on Drupal or some code change. In fact, it is related to Google Chrome's browser update.
Currently Google Chrome's latest version is 44.0.2403.89. The previous version I was running was 43.0.2357.132. Tables on my site were displaying just fine. And actually, after hours of troubleshooting, I thought to just check the website with Safari and sure enough things were displaying as they always have. Then I checked Firefox, also no problem and displayed as it had. So it seems Google has changed something in Chrome to cause tables to break. Any idea what's going on and how I can fix it, or is this a bug with the latest Chrome version?
Here is a sample of the table being broken by Chrome:
http://www.yoninja.com/jp/browse/results/taxonomy%3A74
See how the middle column's table flows under the right side bar. If you check this page with the previous version of Chrome (43.0.2357.132), it displays just fine. Also displays perfect in Safari and Firefox's latest version. What gives?!?
* UPDATE *
So I have temporarily fixed it by using Drupal's View Theming and modifying the views-view-table--(viewname).tpl.php file and editing the column width of the column which holds the long text. Even specifying the table width, whether with a percentage or a specific width in pixels, doesn't work in the latest Google Chrome.
<table class="<?php print $class; ?>"<?php print $attributes; ?> style="width:770px;">
<table class="<?php print $class; ?>"<?php print $attributes; ?> style="width:100%;">
Neither of these work, specifying 100% doesn't change a thing. Specifying the width in pixels actually does change the width of the table but not the by the width you specify. Strange! Why would Google's update change the behavior of something that has already been working previously?
Anyway, the only way I have been able to get things working is by specifying the width of the column as mentioned below in one of the answers. However, I still feel this is unnecessary and it seems every other browser is still displaying tables properly. So the question is, will Google fix this?
Is there anyone I can get this working without having to specify the table width. I use this view in various pages, and I don't want to have to worry about specifying the width.
This has indeed been reported as a bug.
https://code.google.com/p/chromium/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Cr%20Status%20Owner%20Summary%20OS%20Modified&groupby=&sort=&id=512872
This bug seems to apply to tables who's width has been specified but rely on automatic width calculations on individual table divisions with larger amounts of text in them. It miscalculates the width table divisions which contain larger amounts of texts. Affected rows now extend beyond the edge of the table visually breaking column alignment.
Until a valid update to Chrome fixes this, you can apply my earlier posted work around.
You'll need to manually specify the width of table divisions which contain large amounts of text in them (not the table itself). This will override the invalid calculation and prevent your table row from expanding beyond the width of the table.
I've tested this with an inline width specifier on table divisions with large amounts of text in them.
<table>
<tr>
<td>
some stuff
</td>
<td width='30%'>
some other large text field whose width isn't calculated properly
</td>
</tr>
</table>
I too have experienced this issue. It does indeed seem to be an update from 43 to 44 that changed the layout behavior. My site used the automatic layout to re-size the width which no longer works well. The fix for our site was to set one of the larger text fields width with an inline width element on the table division.
Your mileage may vary.
<table>
<tr>
<td>
some stuff
</td>
<td width='30%'>
some other large text field whose width isn't calculated properly
</td>
</tr>
</table>
After the Chrome 44.0.2403.89 update pages containing an html table with a style of width:100% (or using bootstrap table classes) no longer honor the 100% width if ANY of the columns contains a "long" string (even if the string includes spaces). This is new behavior and I've confirmed it is directly related to the 44 update. Hopefully if enough people post it will get fixed.
I am having the same issue which broke our page layout.
However, I actually am using a fixed width CSS property on the table.
The width of the table is visibly larger than the width specified. (I.E., it overflows.)
Querying the width of the table with JS returns the CSS width set, not the real width.
I have an application that generates tables for reports; however during printing - the tables may get split, which causes some of the information to get cut off ( I mean it's only printing the top half of letters and then getting split to the next page ).
I've tried page-break-before ; however that causes every table to be on it's own page. page-break-inside seems to be only supported by Opera (And I'm not even sure if that's what I want).
What I'm hoping to find, is something that if the entire table cannot be fit onto a page - it is pushed to the next; or better yet - if the next row is started on the next page.
Any help would be appreciated!
Use Javascript:
Parse data inpage and reformat
Get table height
If table height > page allowed height = add a new table
Each page fits into:
div.page {
height: 842px;
width: 595px;
}
The simplest way of achieving this is a print button that opens a new page, the data is there in a format that Javascript can convert it into a table.
This is the only real accurate way I know of configuring a page of data that splits in tables.
I have a table with column contents that could be potentially long. From a design/usability standpoint, is it better to wrap the text or provide a scroll bar within the column to view the entire text?
Personally, I think wrapping the text is better. But I wanted to know what have others done in such a situation?
I ALWAYS page my content rather than wrapping or scrolling. It's super easy with jQuery DataTables and it gives the user further opportunities to filter, limit, and sort the data.
This solution also gives you the option to scroll data as well, and to dynamically adjust columns or do show/hides. But I've never gotten to that point. One one of my applications, using Ajax and Pipelining (which are supported by the plugin) it handles 3+ million records without a hiccup. Also, note that it can use jQuery's Themeroller, which can style the table simply and even from the user end on the fly if so desired.
I usually let the text wrap into the cell. But, what do you mean by "potentially long"?
I use a calendar plugin and sometimes the title gets long- i made the decision to break the string in the middle if needed- Supported in CSS3 only- other wise it just wraps
My css
.fc-event-title {
text-wrap: unrestricted;
word-wrap: break-word;
}
and will only happen if mywordisexteremlylong and wont fit properly in a small cell
But this is very extreme so that it does not overflow into the next cell.
But otherwise i dont break the word if there is enough space.
I'm new on this particular project, and I've been tasked with resolving an issue that's appearing in IE8.
If you check http://funds.ft.com/ETFHomepage.aspx, There's a section called "News". In that section, there's a column called "Most Popular ETFs". This should be the same width as the "Recently Viewed ETFs" column.
For reference, this page is appearing correctly in Firefox. Can somebody please point out what I can do with CSS or (some other means)* to resolve this?
*I know the best way to resolve this issue is to scrap the terrible design and implement it correctly!! :-) -- we're actually doing that right now. It's a big job, so it's taking a long time. In the mean time however, we have to fix the bugs as they appear. Thanks
Update: just to note what I've said to Hristo, "I think the problem is with the table (rather, nested tables) on the left. The table in the center has its width defined by the image, and the table on the right doesn't have an image so it gets crushed"
Well the reason this is happening is because of the url you have under the "Alphaville: Overcoming the Volcker rule, with ETFs" header. Since the url has no whitespace in it, the table tries to give it space. So there are a couple of ways to fix this problem:
Plain text urls aren't very becoming on a webpage (especially when they're not in anchor tags so you can click on them.) Could you update the content so that you don't have a raw url in your content?
If you must be able to handle long lines of text with no whitespace then you need to figure out how to change the layout of the page so it forces the text to either wrap or clip to fit the container. Try playing around with putting "table-layout: fixed" on your tables to force the column widths to be sized based on the table's specifications only (instead of content). Firefox seems to be wrapping on dashes and slashes in the url whereas IE only wants to wrap on the dashes in the url.
I would say your layout is fine, and you just need to fix the content generation so it doesn't include any long plain text urls (option 1 above)
EDIT: If you do decide to go with option 2 above, then look into the css rule "word-break: break-all". It is IE only and it forces the text to break as soon as it reaches the end of the container. Not good for words, but it works for url's. So you couldn't apply this to the whole news table, but you could to just the cell that contains the url.