Friday 12 July 2013

Display Visual force Reports  with different Colors alternate rows :


url :  http://apl-developer-edition.ap1.force.com/LatestRecords

page:
<apex:page controller="Latest_record" action="{!displayRecords}">
    <style>
        table tr:nth-child(even) {
       background: #C3FAF6;
        }
        table tr:nth-child(odd) {
   
        }
    </style>


    <apex:form >
   
            <center ><b><font size="5px">Case Report!</font></b></center>
            <table width="100%" border="0.5" cellspacing="0">
                <tr bgcolor="#FABA0A">
                    <th>Case ID</th>
                    <th>Date/Time Opened</th>
                    <th>Date/Time Closed</th>
                    <th>Status</th>
                    <th>Priority</th>
                    <th>Type</th>
                    <th>Description</th>
                </tr>
                <apex:repeat value="{!lstrecords}" var="r" >
                    <tr height="50">
                        <td >
                            <apex:outputField value="{!r.id}"/>
                        </td>
                        <td>
                            <apex:outputField value="{!r.CreatedDate}"/>
                        </td>
                        <td>
                            <apex:outputField value="{!r.ClosedDate}"/>
                        </td>
                        <td>
                            <apex:outputField value="{!r.Status}"/>
                        </td>
                        <td>
                            <apex:outputField value="{!r.Priority}"/>
                        </td>
                        <td>
                            <apex:outputField value="{!r.Type}"/>
                        </td>
                        <td>
                            <apex:outputField value="{!r.Description}"/>
                        </td>
                    </tr>
                     
                </apex:repeat>
             
            </table>
             
     
    </apex:form>

</apex:page>

Class :
public class Latest_record {
    public list<case> lstrecords{get;set;}
    public void displayRecords(){
           
        lstrecords=new list<case>();
        list<string> st=new list<string>{'New','Escalated','Working','Closed'};
        for(string s:st)
        {
            list<case> c=getRecord(s);
            if(c.size()!=0)
            {
                for(case cs:c)
                {
                lstrecords.add(cs);
                }
            }
        }

     
    }
 
    public list<case> getRecord(string val){
     
        string query='select id,createddate,SlaStartDate,ClosedDate,Description,Type,Priority,Status from case where status =:val order by CreatedDate ';
        list<case> caserecord=database.query(query);
        if(caserecord!=null)
        {
        return caserecord;
        }
        return null;
    }
}
Categories: ,

0 comments:

Post a Comment

    Links