primefaces datatable reflow in desktop browser - css

primefaces 5.2
i have a primefaces datatable, the table is very long which is why i want to show it in column stacked mode, i tried using reflow attribute of the datatable.
now if i use the developers mode in chrome and switch to mobile view when i reduce the size of the screen it does in fact behave responsive and goes into stacked column mode, now i want to show that type of table in normal desktop view as well. i thought simple things like just reducing the size of the table would help but no matter how small i reduce the size it just crams the table into that tiny space instead of making it responsive.
am i missing something about how to make something behave responsive on a desktop browser.
<p:dataTable id="tb1" var="ths" value="#{thb.sitetracking}"
rowIndexVar="rowindex" reflow="true"
>
in normal size the table looks like this
in chrome developers mode mobile view
if i resize the table to get the same effect, instead of a responsive size change this happens
<p:dataTable id="tb1" var="ths" value="#{thb.sitetracking}"
rowIndexVar="rowindex" reflow="true" style="width:200px"
>
if i resize my browser with same table above and make it smaller, it works
maybe i am just not understanding what responsive actually means, is it not possible to trigger a responsive behaviour by changing the size of the table, it seems to only work when the size of the browser changes
My main objective of doing this doesn't really have much to do with making the table responsive the real thing that i want to achieve is getting the table into column stacked mode and from what i have seen this is the only way PF does it
any help would be appreciated

Reflow mode works with CSS media query. When your window width is less than 35em (see also the primefaces.css snippet below) then reflow mode is applied.
Thus, applying a width: 200px; to your dataTable isn't taken into account and will not result in a stacked datatable.
To achieve your goal (applying stack mode when your window width is larger than 35em) you could create (I can't figure out a cleaner solution) your own css class which got rid of the media query. Something like table-reflow-desktop:
.table-reflow-desktop .ui-datatable-data td .ui-column-title {
display: none;
}
.table-reflow-desktop thead th,
.table-reflow-desktop tfoot td {
display: none;
}
.table-reflow-desktop .ui-datatable-data td {
text-align: left;
display: block;
border: 0px none;
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
float: left;
clear: left;
}
.table-reflow-desktop .ui-datatable-data.ui-widget-content {
border: 0px none;
}
.table-reflow-desktop .ui-datatable-data tr.ui-widget-content {
border-left: 0px none;
border-right: 0px none;
}
.table-reflow-desktop .ui-datatable-data td .ui-column-title {
padding: .4em;
min-width: 30%;
display: inline-block;
margin: -.4em 1em -.4em -.4em;
}
And don't forget to apply this class to your p:dataTable:
<p:dataTable id="tb1" var="ths" value="#{thb.sitetracking}" rowIndexVar="rowindex" styleClass="table-reflow-desktop">
For reference, here is the original PrimeFaces 5.2 css part which is responsible of the reflow mode:
/** Reflow **/
.ui-datatable-reflow .ui-datatable-data td .ui-column-title {
display: none;
}
#media ( max-width: 35em) {
.ui-datatable-reflow thead th,
.ui-datatable-reflow tfoot td {
display: none;
}
.ui-datatable-reflow .ui-datatable-data td {
text-align: left;
display: block;
border: 0px none;
width: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
float: left;
clear: left;
}
.ui-datatable-reflow .ui-datatable-data.ui-widget-content {
border: 0px none;
}
.ui-datatable-reflow .ui-datatable-data tr.ui-widget-content {
border-left: 0px none;
border-right: 0px none;
}
.ui-datatable-reflow .ui-datatable-data td .ui-column-title {
padding: .4em;
min-width: 30%;
display: inline-block;
margin: -.4em 1em -.4em -.4em;
}
}

Related

CSS Border radius, border color ghost corner borders in IE

Morning,
I have the following code that works in all browsers other than IE. I want a blue border to appear when clicking on input boxes, however did not want to see the elements resizing and positioning. I fixed this by putting a border colour to match the background colour, thus removing the resizing effect. However, on IE, you get ghost borders which seem to be a combination of both the border radius and border colour (background colour). Any ideas of how to fix this without using box shadow?
Screen Shot showing ghost borders:
input,
textarea,
select {
position: relative;
display: block;
border: 3px solid #4f4f4f;
border-radius: 10px;
margin: 6px auto 22px auto;
width: 260px;
font-size: 13px;
text-align: center;
&:focus {
outline: none;
border: 3px solid #4cc7fa;
}
}
Many thanks!
You can do like this to overcome the ghost/resize/re-positioning effect, where you change border-width on focus and compensate its re-positioning with a negative top
body {
background: gray;
}
input,
textarea,
select {
position: relative;
display: block;
border: 0px solid gray;
border-radius: 10px;
margin: 6px auto 22px auto;
width: 260px;
font-size: 13px;
text-align: center;
}
input:focus {
top: -3px;
outline: none;
border: 3px solid #4cc7fa;
}
<input type="text">
I would use the following javascript:
Your-function() {
document.getElementsByTagName('input','textarea','select').classlist.toggle('show')
}
add display:none to input:focus
add the following css
.show
{
display:block;
}
Note: Add onclick="Yourfunction()" to your markup to load the js.

Is there a clean way to get borders on a <tbody /> in pure CSS?

I'd like to set a background and a rounded border on a <tbody/>, such as
tbody { border-radius: 15px; border: 1px solid black; background: #ccf; }
However, when I try this in Codepen, the border and background color display, but the <tbody/> still has square corners.
I'm able to work around this problem using a series of :last-child and :first-child selectors to apply the radius to individual tds on the corners, as for example
tbody tr:first-child td:first-child { border-top-left-radius: 15px; }
This version does what I want (at least, under firefox) but also feels extremely verbose and hacky, a problem that'll only get worse when I add the prefixed versions for compatibility (-moz-, -webkit- etc), and support for <th/> elements in addition to <td/>. Is there a succinct, pure-css way of getting this behavior?
Assuming you have collapsed the borders in the table, simply set display:block on the tbody and apply the border-radius.
Codepen example
CSS
table {
width: 100%;
border-collapse: collapse;
display: block;
width: 600px;
}
tbody {
background: #ccf;
border: 1px solid black;
border-radius: 15px;
display: block;
}
th, td {
width: 200px;
}
td, th {
padding: 5px;
text-align: center;
}

CSS box-sizing messing with form heights

I've uploaded this question a while ago but it ended up giving me the tumbleweed badge so I'm trying again.
I'm going through Michael Hartl's railstutorial right now and I've encountered a problem where box-sizing property is interfering with form heights as shown in pictures below.
#mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
height: auto;
margin-bottom: 15px;
#include box_sizing; <--- this line here is causing issues
}
(box-sizing property in effect)
(box-sizing property not in effect)
Notice how much smaller forms are when box-sizing property is in effect? You can't really view full letters because the height is so low. I've tried to change the height property under input, textarea, ..etc. but it seems like my code is being overridden by Bootstrap. If you have any idea how to make the forms bigger (greater height) I would really appreciate it.
box-sizing: border-box changes the box model so padding is taken out from the height, rather than adding to it.
So this block:
div {
box-sizing: content-box; // default
height: 2em;
padding: .25em;
}
Will be 2.5em tall, and this block:
div {
box-sizing: border-box;
height: 2em;
padding: .25em;
}
will be 2em tall, with .5em of spacing partitioned for the padding.
The other issue is how bootstrap defines the height of inputs:
input[type="text"], ...other selectors..,
.uneditable-input {
display: inline-block;
height: 20px;
...
}
The reason defining a height wasn't working, is because input[type="text"] is more specific than input, and therefore the bootstrap declaration was overriding yours.
To solve the problem you are having with the inputs, define a height and use a more specific selector:
input[type="text"], textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
height: 2em;
margin-bottom: 15px;
#include box_sizing;
}
Demo

How can I workaround this CSS anomaly?

I have what I think is some pretty basic css, and it behaves differently in FF4 and IE8.
The CSS in question is like this:
div.showme {
border: 1px dotted blue;
position: absolute;
top :10px;
bottom :10px;
left: 1%;
right: 33%;
overflow: auto;
padding: 0.8em 1em 0.8em 1em;
line-height:1.75em;
}
div.showme a {
padding: 0em 5px 0em 5px;
margin: 0;
white-space: nowrap;
color: #FF00FF;
background-color:#E6E6FA;
border: 1px solid grey;
padding: 0em 4px 0em 4px; }
div.showme a:link { color: blue; }
div.showme a:visited { color: #1E90FF; }
div.showme a:active { color: red; }
The relevant HTML looks like this:
<div class='showme'>
<a href='one'>one</a>
<a href='two'>two</a>
...
</div>
The problem is, the padding is not consistently displayed, in IE8.
In Firefox, it works as I would expect.
working example:
http://jsbin.com/ogosa4
Using the above working demonstration, if you resize the window you will see the padding on the "leading" element on each line within the div, change from zero to non-zero.
How can I fix this?
If you add display: inline-block; to your div.showme a {} the padding will be applied in IE also, but it has some impact with the line height and you may need to specify additional margin's
I have seen this behaviour in Opera too. The padding goes to the upper line. Try display: inline-block and white-space:nowrap if you have more than one word in the link...
You can safely use inline-block in IE7 with inline tags.

How to control the layout in JSF?

I am writing a web application (While learning JSF from scratch, and thanks to this site I was able to do this).
I have managed to get pretty far but there is something I can't figure how to approach to.
Currently I have this:
Link to full size screenshot
As you can see, I don't know how to place things where I want them.
At this point just stacking the buttons (sleep timer and message text) and the input-spinner at the top of each panel would suffice, but I would like to learn how to control this better. (Place each component at a chosen location inside the panel)
The JSP code:
<h:panelGrid id="ActionsPanel" styleClass="leftcol"
binding="#{actions.actionPanel}">
</h:panelGrid>
<h:panelGrid id="EditPanel" styleClass="rightcol"
binding="#{actions.editorPanel}">
</h:panelGrid>
And the CSS:
.leftcol {
display: block; width : 20%;
height: 300px;
float: left;
border: 1px solid #000;
width: 20%; height : 300px; float : left; border : 1px solid #000;
border-top: 0;
}
.rightcol {
width: 70%;
height: 300px;
float: left;
border: 1px solid #000;
border-top: 0;
border-left: 0;
}
Thanks!
Ben.
When writing CSS, don't look at JSF source code, but at its generated HTML output. The h:panelGrid renders a HTML table. You need to vertical-align the contents of the table cells td to top.
.leftcol td {
vertical-align: top;
}
.rightcol td {
vertical-align: top;
}

Resources