Reply
Trusted Contributor
Shiv Shankar
Posts: 162
0

alternate color for table row.

Hi i have created a one visual force page whic is rendering as PDF.

In this one table is rendering dynamicaly(not a apextable). I want to show table row in alterante color. i found some line of code which used JQuery, this works fine when i render as html but now when , i render it as 'PDF'

 

$(document).ready( function(){

$("#myTable tbody tr:visible:even",this).css('background-color','#fffffe');
$("#myTable tbody tr:visible:odd",this).css('background-color','#e0dfde');
}
)

 

Please tell solution ASAP.

SalesForce Developer

Hit the Kudos button (star) if any post helps you - Mark the answer as solution, It might help others running to into similar problem in future.
Moderator
bob_buzzard
Posts: 6,407
0

Re: alternate color for table row.

You won't be able to do this via jquery, or any kind of javascript, as there isn't a javascript engine associated with PDF renderers.  You'd need to do this via CSS - there's a soluton at:

 

http://stackoverflow.com/questions/3084261/alternate-table-row-color-by-css

 

but note that IE and some firefox versions don't support this.

--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.

Regular Contributor
AT-Greg
Posts: 86
0

Re: alternate color for table row.

Hello.

 

I know this thread is a couple of months old, but I had a similar requirement and found a solution that worked for me.

 

In my case, my Visualforce page is controlled by a custom controller and is rendering as a PDF. In my controller, I have a wrapper class that, in addition to the object that I'm returning, also includes an "index" integer that's incremented for each record returned. A sample wrapper class is defined below:

 

    private class objWrapper {
        public Custom_Object__c deal {get;set;}
        public Integer index { get;set;}
        public objWrapper(Custom_Object__c d, Integer i){
            obj = d;
            index = i;
        }
    }

 

Then, in the Visualforce page, in the <apex:repeat> loop, I'm performing a simple MOD function to determine if the index is odd or even, and applying an "altRow" class on even rows:

 

	<table>
		<apex:repeat value="{!getterClassHere}" var="d">
		<tr class="{!IF(MOD(d.index,2)==1,'','altRow')}">
			<td><apex:outputText value="{!d.obj.Name}"/></td>
		</tr>
		</apex:repeat>
	</table>

 

 

Hope that helps.

 

-Greg