Adjusting width of column to content in p:dataTable - jsf

I want the columns of my table to adjust its width to the biggest element.
Like doubleclicking an excel-column...
I've tried lots of attributes and solutions of other questions but nothing really did what i wanted.
Here are my settings for the dataTable which is nested in a p:scollPanel:
<p:dataTable scrollable="true" scrollWidth="auto" scrollHeight="390"
tableStyle="width: auto; white-space: nowrap; font-size: smaller"
id=carTable" var="vehicles"
value="#{dgBean.vehicles}">
Using:
primefaces 6.0
jsf 2.2.1
UPDATE:
I don't know why, but it seems like table-layout: auto is not used AND two divs are generated. 1 for the Header of my table and the other for the body of my table.
That's why the first layout I've posted shows up and the header and body fit nicely on their own but the header doesn't fit the body.
Generated HTML:
<div class="ui-widget-header ui-datatable-scrollable-header" style="width: 1199px;">
<div class="ui-datatable-scrollable-header-box" style="margin-right: 15px;">
<table role="grid">
<thead id="j_idt5:j_idt14:carTable_head">...</thead>
</table>
</div>
</div>
<div class="ui-datatable-scrollable-body" tabindex="-1" style="height: 390px; margin-right: 0px; width: 1199px;">
<table role="grid">
<thead class="ui-datatable-scrollable-theadclone" style="height: 0px;">...</thead>
<tbody id="j_idt5:j_idt14:carTable_data" class="ui-datatable-data ui-widget-content" tabindex="0">...</tbody>
</table>
</div>
So it seems like 2 tables are generated. Does anyone have a clue how to fix this using pf?
UPDATE from comment
Applying
.ui-datatable-scrollable-header-box table, .ui-datatable-scrollable-footer-box table, .ui-datatable-scrollable-body table {
table-layout: auto;
}
to the Showcase
produces (deleted my former images as reputation is not high enough for more than 2):
Showcase with edited css

I want the columns of my table to adjust its width to the biggest element.
PrimeFaces DataTable default style uses table-layout: fixed;. So if only that, replace your tableStyle content with table-layout: auto; to make usage of the automatic table layout algorithm as stated on w3schools.com:
The column width is set by the widest unbreakable content in the cells
From everthing you wrote (including comments) until now, I assume you want a vertically and horizontally scrollable DataTable that automatically sizes its columns to its content.
I claim this is not possible with the built in functionalities of PrimeFaces DataTable, because as you allready noted, if you make the DataTable scrollable, the rendered output differs in that there are different tables for the header, body and footer (to make header and footer sticky).
I don't get it why its not working.
Column sizes calculated with the automatic table layout algorithm with table-layout: auto; will differ for all three tables (except they incidentally have the same broadest unbreakable content, like header and footer in ShowCase). The difference in size gets relativated if the table gets broader (because additional space is equaly distributed to the columns), so it might look like everthing is OK as Kukeltje commented. But if you shrink the width of the table, differences get visible.
| broadest content | stretched by 1000
--------------------------------------------------------
| column 1 | column 2 | column 1 | column 2
--------------------------------------------------------
header table | 2 | 3 | 502 | 503
body table | 4 | 6 | 504 | 506
footer table | 2 | 3 | 502 | 503
As you maybe have noticed, the rendered body table also contains the header content but hidden. So assumed the header content would be broader than the body content, everything would be fine at least for the header and body table.
| broadest content
========================================
| column 1 | column 2
========================================
header table | 5 | 7
----------------------------------------
hidden header part | 5 | 7
body part | 4 | 6
________________________________________
body table | 5 | 7
----------------------------------------
footer table | 2 | 3
The easiest workaround is to disable scrollability and enable pagination. With this, you have a more or less controllable height of the DataTable (with rows attribute) while preserving the remaining requirements.
From my point of view the paginator looks like it is just replacing the vertical scrolling.
More or less (therefore the easiest workaround). Most important thing is that only one table is renderd and therefore header, body and footer content is used to calculate the column widths:
| broadest content
---------------------------------
| column 1 | column 2
---------------------------------
header part | 2 | 3
body part | 4 | 6
footer part | 2 | 3
_________________________________
full table | 4 | 6
How does that aid my horizontal problem?
With table-layout: auto; you get horizontal scrolling within the paginator viewport out of the box.
Another approach is to disable scrollability and wrap the DataTable with a ScrollPanel. This has some disadvantages in that the header is scrollable too and there are issues with resizing you have to handle, so I would not recommend it.
Best solution will be a customized renderer (note the hidden header content in the rendered body table if scrollability is enabled and extend vice verca) and/or customized JS/CSS for your DataTable, but thats out of scope of your question.
Easiest solution would be to not insist on automatic column sizing according to table content and take DataTable with scrolling capabilities as is.

i had the same issue header and table content width was different, i created below css and worked like a charm for me, don't have to remove anything like filters or scrollbars
.ui-datatable-scrollable-header-box table th, .ui-datatable-scrollable-footer-box table th, .ui-datatable-scrollable-body table td{
width: 20% !important;
}

Related

How to set header and row heights in Tabulator?

For a custom React component I wrapped Tabulator and would love to support custom heights for a table header and indvidual rows. I only found row resizing in the documentation, but no information about how to set a custom height in the data (or through an API call).
It's not clear to me from your question if you want to control the height of all rows or just particular ones.
If you want to control height based on data you can use a row formatter. Works well in my experience.
There is also this answer about overriding the CSS for rows: Adjust tabulator row height
.tabulator-row {
position: relative;
box-sizing: border-box;
min-height: 22px;
background-color: #fff;
}

Table Format Report in Acumatica

I want to design a report in table format. I am using Panel and Line Control for now, but it's time consuming to adjust. Is there a better way to do this?
Example:
| column1 | column2 | column3 |
| aaaaa1 | sdf | sdfsdf |
| aaaaa2 | sdf | sdfsdf |
| aaaaa3 | sdf | sdfsdf |
The row background color should be alternating (gray & white).
Your question is a bit ambiguous I am going to assume you mean using the Report designer you would like to generate a report that looks like the image below.
That being said you have two different items you have to accomplish the table layout and the alternating Row color.
For the Table Layout
Unless I am missing something this is the easy part you only need to use the field controls and border settings on the controls to generate the grids. I have added a screen cap of the standard layout for the report above in the designer
For the Alternating Row Color
This is the challenge because without a little but of work it cant be done. What you have to do is using the visible expression create two sets of duplicate controls one placed directly on top of each other. I used the row number to build my expression that looked like
=IIf( $RowNumber % 2 = '0', True, False )
=IIf( $RowNumber % 2 = '0', False, True )
That divides each row number by two and if there is a remainder (Bottom equation) shows it and vise versa for the other set of controls.

How to click on a table cell containing known text?

Using Watir, I want to click on a table cell containing the text "ad.03.IL.R.nC.nOwn.Wait"
The HTML is:
<span onclick="javascript:showListMembers(343);" style="text-decoration:none; border-bottom: 1px solid Gray;">ad.03.IL.R.nC.nOwn.Wait</span>
What is the correct Watir statement?
matches = b.spans(:text => "ad.03.IL.R.nC.nOwn.Wait")
Use the plural method unless you're sure there's only one possible match. You can also do regex stuff
matches = b.spans(:text => /ad.03.IL.R.nC.nOwn.Wait/)
Span elements aren't table cells in the proper sense. Table cells don't normally have useful metatags

bbcode : How to draw a table

Is there any way to draw a table in a forum which uses bb code if [Table] tab is not supported ?
The tags being allowed in the forum are :
[b], [i], [u]
[color]
[size]
[font]
[highlight]
[left], [right], [center]
[indent]
[email]
[url]
[thread]
[post]
[list]
[img]
[quote]
[noparse]
[attach]
Do not think so.
But, depending on your purpose, it may be sufficient to force a monotype font (e.g. Courier) using the [font] tag, and then simply "draw" your table by hand using ASCII characters. For example:
[font=courier]
-----------------
| Col A | Col B |
-----------------
| 1 | X |
| 2 | Y |
| 3 | Z |
-----------------
[/font]
Certainly, it is troublesome and may be considered dirty, but your set of available tools is pretty limited.
The [code][/code] tag will maintain white spacing. Example at
http://www.bbcode.org/examples/?id=15. I can see that [code] tags may not be allowed in your forum but are they truly disabled? If so, is there any possibility of turning them on?
Alternatively, I would try Wojciech Żółtak's idea to use a monospaced font.
Finally, you could take a screen cap of the table and insert it as an image. Include the table text as part of the image's alt and/or title tag.

Setting column width in RTF

I have what I hope is a simple question !
I am generating a simple RTF table that is subsequently opened in MS Word. The table is generating fine but the column widths are a little small and causing some word wrapping (not what I want).
The RTF code I generate is for a two line, three column table and is of the form:
\trowd \trautofit1
\intbl
\cellx1
\cellx2
\cellx3
{a\cell b\cell c\cell }{\trowd \trautofit1
\intbl
\cellx1
\cellx2
\cellx3
\row}
\trowd \trautofit1
\intbl
\cellx1
\cellx2
\cellx3
{d\cell e\cell f\cell }{\trowd \trautofit1
\intbl
\cellx1
\cellx2
\cellx3
\row}
What do I need to add to set a column width ? I have tried altering the column width in word and then examining the output but it is a little obscure to say the least !
The control words you are looking for are \clwWidthN and \clftsWidthN
Microsoft RTF Specification v1.9.1:
- \clwWidthN
Preferred cell width. Overrides \trautofitN.
- \clftsWidthN
Units for \clwWidthN:
- 0 : Null. Ignore \clwWidthN in favor of \cellxN (Word 97 style of determining cell and row width).
- 1 : Auto, no preferred cell width, ignores \clwWidthN if present; \clwWidthN will generally not be written, giving precedence to row defaults.
- 2 : Percentage (in 50ths of a percent).
- 3 : Twips.
So, in your case, you could just use \clftsWidth1 (automatically set width) or set the preferred percentages yourself e.g. \clwWidth2\clwWidth2500 (2500 = 50%)
Auto width
\trowd \trautofit1
\intbl
\clftsWidth1\cellx1
\clftsWidth1\cellx2
\clftsWidth1\cellx3
{a\cell b\cell c\cell }
40% - 30% - 30%
\trowd \trautofit1
\intbl
\clftsWidth2\clwWidth2000\cellx1
\clftsWidth2\clwWidth1500\cellx2
\clftsWidth2\clwWidth1500\cellx3
{a\cell b\cell c\cell }
The problem is in that you have set very small width for column:
\cellx1
\cellx2
\cellx3
To set width for column in RTF there is a keyword '\cellxN', where N - is column width in twips.
15 twips is 1px.
So if you want to create a simple RTF table with 1 row and 3 columns, 100px each, use this syntax:
\trowd\cellx1500\cellx3000\cellx4500
\intbl A\cell B\cell C\cell\row
You will get a simple table by 300px, 3 columns - 100px each, with invisible borders.
Cheers,
Max
You need to either use cellx0, so that autofit tag applies, or explicity set the number to the number of twips from the left border. In your example, you use 1 2 and 3 which is explicity setting the column widths to be very skinny. For example, something like:
\cellx5125
\Cellx6000
\Cellx8000
Note that these numbers are offsets from the left margin.
If you are going to do any RTF, I highly recomend the RTF Pocket Guide from O'Rielly
Check this link
http://joseluisbz.wordpress.com/2014/04/26/working-rtf-html-css-and-script-files-with-my-own-packages-java-and-php/
you can to make your own file.
TblData = new RTFTable(4,4); //4 Columns, 4 Rows
TblData.setWideCols(1000); //Width of 2000 to put all columns
TblData.setWideCol(0,3000); //Width of 3000 to Column 0

Resources