function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NervosaNervosa 

Relative position of pageBlockTable and pageBlockSection

Greetings to everyone!

 

Look, here is my VF page:

<apex:page standardStylesheets="false" showHeader="false" sidebar="false" controller="Fullfunctionality_2">
<apex:stylesheet value="{!URLFOR($Resource.Styles, 'styles.css')}"/>
<apex:sectionHeader title="List of items in stock with ADD, DELETE, SORT and SEARCH functions"></apex:sectionHeader>
<apex:form >
<apex:pageBlock >
      <apex:commandButton value="Show items" action="{!ViewData}" >
      </apex:commandButton> 
    <apex:pageBlockTable value="{!items}" var="i" >
    <apex:column >
        <apex:commandLink action="{!del}" value="Delete">
            <apex:param name="idtodel" value="{!i.id}" assignTo="{!IDToDel}"/>
        </apex:commandLink>
    </apex:column>
       <apex:column style="text-align:left">
         <apex:facet name="header">   
           <apex:commandLink action="{!ViewData}" value="Item name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'')}" style="color:yellow">
             <apex:param value="name" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
         <apex:outputText value="{!i.name}"></apex:outputText>
       </apex:column>
       <apex:column style="text-align:left">
           <apex:facet name="header">
               <apex:commandLink action="{!ViewData}" value="Price{!IF(sortExpression=='Item_Price__c',IF(sortDirection='ASC','▼','▲'),'')}" style="color:yellow">
                   <apex:param value="Item_Price__c" name="column" assignTo="{!sortExpression}"/>
               </apex:commandLink>
           </apex:facet>
           <apex:outputText value="{!i.Item_Price__c}"/>
       </apex:column>
       <apex:column >
           <apex:facet name="header">
               <apex:commandLink action="{!ViewData}" value="Adding date{!IF(sortExpression=='createddate',IF(sortDirection='ASC','▼','▲'),'')}" style="color:yellow">
                   <apex:param value="createddate" name="column" assignTo="{!sortExpression}"/>
               </apex:commandLink>
           </apex:facet>
           <apex:outputText value="{0,date,MM/dd/yyyy}">
               <apex:param value="{!i.createddate}"/>
           </apex:outputText>
       </apex:column>
    </apex:pageBlockTable>
    <apex:pageBlockSection columns="1">
    <apex:inputText value="{!NewItemName}" label="Name" style="text-align:left"/>
    <apex:selectList id="types" size="1" required="true" label="Type" >
        <apex:selectOptions value="{!types}"/>
    </apex:selectList>
    <apex:inputText value="{!NewItemPrice}" label="Price" style="text-align:left" />
    <apex:inputText value="{!NewItemQuantity}" label="Quantity" style="text-align:left"/>
    <apex:inputText value="{!NewItemReleaseDate}"  label="Release Date"/>
    <apex:commandButton value="Add item" action="{!add}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 And its APEX controller:

public class Fullfunctionality_2 {
 
   private List<Item__c> items;
   private String sortDirection = 'ASC';
   private String sortExp = 'name';
   public String NewItemName {get; set;}
   public Integer NewItemQuantity { get; set; }
   public Integer NewItemPrice { get; set; }
   public String NewItemType { get; set; }
   public Date NewItemReleaseDate { get; set; }
   public String IdToDel { get; set; }

   public List<SelectOption> getTypes(){
       List<SelectOption> types = new List<SelectOption>();
       Schema.DescribeFieldResult fieldResult = Item__c.Item_Type__c.getDescribe();
       List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
       for( Schema.PicklistEntry f : ple)
           {
              types.add(new SelectOption(f.getLabel(), f.getValue()));
           }       
       return types;
    }
    
   public PageReference add(){

        Item__c NewItem = new Item__c(            
                Name = NewItemName,
                Item_Price__c = NewItemPrice,
                Items_Available__c = NewItemQuantity,
                Item_Type__c = NewItemType,
                Release_Date__c = NewItemReleaseDate);
                insert NewItem; 
                PageReference curPage = ApexPages.currentPage(); 
                curPage.getParameters().put('success','true');
                curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
                curPage.setRedirect(true);
                return null; 
    }     
   public PageReference del() {

        Item__c ItemToDel = [SELECT id
                             FROM Item__c
                             WHERE id = :IdToDel];
        delete ItemToDel;                     
        PageReference curPage = ApexPages.currentPage(); 
        curPage.getParameters().put('success','true');
        curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
        curPage.setRedirect(true);
        return curPage;
            
    }    

   public String sortExpression
   {
     get
     {
        return sortExp;
     }
     set
     {
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }

 public String getSortDirection()
 {
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }

 public void setSortDirection(String value)
 {  
   sortDirection = value;
 }
  
   public List<Item__c> getItems() {
       return items;
   }

   public PageReference ViewData() {
   
       string sortFullExp = sortExpression  + ' ' + sortDirection;
       items = Database.query('Select id, Name, Item_Price__c, CreatedDate from Item__c order by ' + sortFullExp + ' limit 1000');
       return null;
   }
}

 I have some questions.

1) As you can see there are such elements like pageBlockTable and pageBlockSection. When VF page is being rendered pageBlockSection is situated below pageBlockTable. And I want it to be situated to the right to pageBlockTable. How can i do it?

2) When i add or delete an item the page reloads and i see only header of pageBlockTable. The same occurs when i load page for the first time during the session. How can i avoid it?

 

Thanks in advance.

NervosaNervosa

I wrote: " How can i avoid it?". I meant I want it to be shown constantly and reloaded with the whole page.

sivaextsivaext

hi

 

try this

 

1. if you want side by side page block table and page block section , use with html <div> tags

2. if you want default loads of table , try call  list into construtor.