Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix the column width of <p:panelGrid>?

I am working on JSF application in that I am just having a doubt in adjusting the column width in panelGrid.

My code is :

<p:panelGrid id="grid" columns="2" cellpadding="5"  styleClass="panelGrid"
    style="border:none;margin:0 auto;width:500px;"   >  
    <p:column style="width:250px">
        <h:outputText value="To :" />
    </p:column>    
    <p:column style="width:250px">
        <h:outputText value="#{bean.name}" />
    </p:column>    
    <p:column style="width:250px">
        <h:outputText value="Address :" />
    </p:column>  
    <p:column style="width:250px">
        <p:outputLabel value="#{bean.address}" />  
    </p:column>
</p:panelGrid>

Here I want to fix the width if first column for 250px, so I mentioned

<p:column style="width:250px">

I tried

  • how can I adjust width of <p:column> in <p:panelGrid>?
  • How can I change column width of panel grid in PrimeFaces

But it is not working, column width is varying depend upon second column. Can anybody say why it is happening? Or suggest any other way to do this.

like image 903
kark Avatar asked Jan 12 '23 04:01

kark


2 Answers

I suggest you to use both <p:row /> and <p:column /> as it is described in Showcase. With <p:row /> I managed simmilar css problem to work. Like this:

<p:panelGrid id="grid" columns="2" cellpadding="5"  styleClass="panelGrid" style="border:none;margin:0 auto;width:500px;"   >  
   <p:row>
      <p:column style="width:250px">
         <h:outputText value="To :" />
      </p:column>    
      <p:column style="width:250px">
          <h:outputText value="#{bean.name}" />
      </p:column> 
   </p:row>
   <p:row>
       <p:column style="width:250px">
        <h:outputText value="Address :" />
      </p:column>  
      <p:column style="width:250px">
        <p:outputLabel value="#{bean.address}" />  
      </p:column>
   </p:row>
  </p:panelGrid>
like image 166
miroslav_mijajlovic Avatar answered Jan 17 '23 16:01

miroslav_mijajlovic


It's not very advisable to use fixed width. I suggest you use ui-grid-col css class as described in primefaces showcase .

<div class="ui-grid ui-grid-responsive">
 <div class="ui-grid-row">
  <div class="ui-grid-col-3">
     <h:outputText value="To :" />
  </div>    
  <div class="ui-grid-col-3">
      <h:outputText value="#{bean.name}" />
  </div> 
</div>
<div class="ui-grid-row">
   <div class="ui-grid-col-3">
    <h:outputText value="Address :" />
  </p:column>  
  <div class="ui-grid-col-3">
    <p:outputLabel value="#{bean.address}" />  
  </div>
</div>

like image 32
andolsi zied Avatar answered Jan 17 '23 15:01

andolsi zied