Monday, March 11, 2013

Displaying the Account records background color in Visualforce Page

Ex:1

Visualforce Page:

<apex:page controller="recordscls" >
<style>
    .col1{
        background-color:yellow
            }
    .col2{
        background-color:red
           }
    .col3{
        background-color:green
            }
</style>
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockTable value="{!accs}" var="a" columnClasses="col1, col2,col3">
              <apex:column headerValue="Account Name">
                  <apex:commandLink value="{!a.name}" action="{!redirect}">
                      <apex:param value="{!a.id}" assignTo="{!accountid}" name="p1"/>
                  </apex:commandlink>
              </apex:column>
              <apex:column value="{!a.phone}"/>
              <apex:column value="{!a.fax}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>
  </apex:form>
</apex:page>

Apex Class:

public with sharing class recordscls {
    public PageReference redirect() {
        System.debug('---------->'+accountid);
        pagereference ref = new pagereference('/'+accountid);
        return ref;
                                                     }
public List<Account> accs{get; set;}
public recordscls(){
    accs =[Select id, name, phone,fax from Account];
                            }
public string accountid{get; set;}
                                                       }

Ex:2

Visualforce Page:

<apex:page standardController="Account" extensions="recordcls" recordSetVar="accs" id="page">
    <style>
    .col1{
        background-color:yellow;
            }
    .col2{
        background-color:red;
            }
    .col3{
        background-color:green;
            }
    .listViewport .x-grid3-row-over, .errorConsole .x-grid3-row-over, body .pbBody table.list tr.dataRow.highlight td, body .pbBody table.list tr.dataRow.highlight th {
background-color: red !important;
}
</style>
<script>
    window.onload=function(){
       // alert('Hi Good MOrning');
       // alert('{!accs}'); 
    }
</script>
    <apex:form id="form">
        <apex:PageBlock id="pb">
            <apex:pageBlockTable value="{!accs}" var="a" columnClasses="col1, col2,col3" id="pbt">
                <apex:column headerValue="Account Name" >
                    <apex:commandLink value="{!a.name}"/>
                </apex:column>
                <apex:column value="{!a.phone}"/>
                <apex:column value="{!a.fax}"/>
            </apex:pageBlockTable>
            <br/>
            <div align="center">
            <apex:commandLink value="Previous" action="{!previous}"/> &nbsp; &nbsp;
            <apex:commandLink value="Next" action="{!next}"/>
            </div>
       </apex:PageBlock>
    </apex:form>
</apex:page>

Apex Class:

public with sharing class recordcls {
    public recordcls(ApexPages.StandardSetController controller) {
        controller.setPagesize(5);
                                                                                                   }
                                                     }

No comments:

Post a Comment