How to right align in apex:pageBlockTable?

How to right align in apex:pageBlockTable?

Sample Code:

Visualforce page:


<apex:page controller=”Sample”>
    <style type = “text/css”>
        .colHeadr {text-align:center;}     
    </style>
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:pageBlockTable value=”{!listEmp}” var=”e” border=”1″>
                <apex:column dir=”RTL” value=”{!e.Name}”/>
                <apex:column dir=”RTL” value=”{!e.Age__c}”/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Apex Class:

public class Sample {
    public List<Employee__c> listEmp {get;set;}
    public Sample() {
        listEmp = new List<Employee__c>();
        listEmp = [SELECT Name, Age__c FROM Employee__c];
    }
}

Note: This dir attribute is not applicable for header.

If the above code is not working, try the below code

<apex:page controller=”Sample”>
    <style type = “text/css”>  
        .rightAlign {text-align:right;} 
    </style>
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:pageBlockTable value=”{!listEmp}” var=”e” border=”1″>
                <apex:column dir=”RTL” value=”{!e.Name}”/>
                <apex:column dir=”RTL” value=”{!e.Age__c}” styleClass=”rightAlign”/>
            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Cheers!!!

Leave a Reply