3

I have a table with rows, i want to highlight the selected row to do some actions on it. I used onRowClick and give it background color, but if i click on anothe row, it highlight two rows .. how to clear the last style or just highlight single row !

here is my code in VF

<apex:pageBlockTable id="countriesTable" 
                     value="{!Countries}" 
                     var="c" 
                     onRowClick="style.backgroundColor='yellow'" >

screenshot enter image description here

3

You need to "notice" somehow the last clicked row and then if a next one is clicked just clear the background color of that row:

<script>
var lastRow;
function highlight(elem){
    if(lastRow != undefined)
        lastRow.style.backgroundColor = 'white';

    elem.style.backgroundColor = 'yellow';
    lastRow = elem;
}
</script>

<apex:pageBlock>
<apex:pageBlockTable value="{!list1}" var="item" rules="rows" id="myTable1" onRowClick="highlight(this);">
    <apex:column value="{!item.id}"/>
    <apex:column value="{!item.name}"/>
</apex:pageBlockTable>    
</apex:pageBlock>
  • Thank you @mast0r, but could you help me in this issue, after highlighting row, i used actionSupport with event onRowClick to define a parameter <apex:param ..>, but does not work because there is tow events "onRowClick" .. Could you help me ? – user3003810 Mar 31 '14 at 13:09
  • Your intelligence leaves me dumbfounded yet again! Kudos! – Sam Jul 10 '14 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.