0

I'm having a requirement to highlight the apex:column in apex:pageblocktable when a particular record is selected.

So I kept a checkbox which is disabled and when I select a record, the disabled field should become true. How can I achieve this?

Here is the code:

  <apex:pageblockTable value="{!accList}" var="acc"  >
        <apex:column headerValue="Action"  ><apex:inputCheckbox value="{!acc.Check_Box__c}" disabled="true" style="color:grey;backgroundcolor:grey;" /></apex:column>
<apex:column headervalue="Group #"  ><apex:commandlink value="{!acc.AccountNumber}" action="{!ViewAccRecord}" rerender="thetable"><apex:param id="AccId" name="AccViewId" assignto="{!AccRecId}"  value="{!acc.id}"/></apex:commandlink></apex:column>
    </apex:pageblockTable>
6
  • You should add JavaScript or Jquery code to highlight the row. How does disabling a button helps here? how can you select a record if its disabled?
    – Raul
    Commented Jan 24, 2017 at 10:53
  • What do you mean by "select a record"? Your checkbox is initially disabled, so there must be something else to select a record. Commented Jan 24, 2017 at 10:54
  • I just want to let the user know that the record is selected by enabling the checkbox to true. Can I do this by javascript.I have disabled the checkbox because I don't want the user to change the value.Anyways highligting the record I have already done it by using the javascript
    – Rv1
    Commented Jan 24, 2017 at 10:57
  • yes .A hyperlink is added. I have updated the code
    – Rv1
    Commented Jan 24, 2017 at 10:58
  • The hyperlink that you added should take you to the account detail page, not related to your issue. On which event do you know a record is selected and then you will enable the checkbox? Commented Jan 24, 2017 at 11:19

1 Answer 1

0

Have this on your outputLink element

onclick="jsFunc('{!acc.Id}');return false;"

It will pass the account Id of the current row to the jsFunc, the JS function.

Next, on the inputCheckbox put the account id in the styleClass attribute.

<apex:inputCheckbox styleClass="{!acc.Id}" disabled="true"

Sorry for this 'unethical' usage of styleClass. I will keep looking for other ways to do this and will update the answer.

Next, the js function.

function jsFunc(accId)
{
    document.getElementsByClassName(accId)[0].disabled = false;
}

------------ OR -----------------

You can have a wrapper class for this requirement like this.

public AccountWrapper
{
    public Account acc;
    public Boolean isSelected;
}

So the pageBlockTable will loop through a list of the AccountWrapper objects with isSelected initialized to false for all.

So your vf will look like this.

<apex:pageblockTable id="pgBlkTable" value="{!accWrapList}" var="accWrap"  >
    <apex:column headerValue="Action"  >
    <apex:commandLink ..... reRender="pgBlkTable" >click here</apex:commandlink>
    <apex:inputCheckbox  disabled="{!IF(accWrap.isSelected==false, true, false)}" style="color:grey;backgroundcolor:grey;" />

So in your ViewAccRecord function you change the isSelected value of the selected record to true, and the rest will be taken care of by the reRender attribute of outputLink.

2
  • or else can I make the checkbox to true when i click on the record and give it to the user as readonly so that they will be not editing the field.Can you please modify your code accordingly
    – Rv1
    Commented Jan 25, 2017 at 6:18
  • document.getElementsByClassName(checkbx)[0].checked = true; have this in your JS function, you should be good to go. Commented Jan 25, 2017 at 8:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .