1

I have a Visualforce page with a header section that has a checkbox, and a detail section with a table that has a checkbox in the first column. Based on the data loaded the checkboxes in the table are either checked or unchecked.

enter image description here

When the header checkbox is ticked on the VF form, it hides/shows the rows in the table that have no check. The problem is when I do anything on the page and it reloads, it resets it to the default (which is to show all).

How can I control the header checkbox from within my Controller? I can check or uncheck the header checkbox from the Controller, but I can't simulate the 'click' for it to run the javascript code that does the hide/unhide. How can I do this?

My javascript:

jCC$(".hideContacts").click(function() {

    var isChecked = this.checked;
    if(isChecked){
        jCC$(".dataRow").each(function() {
            var c = jCC$(this).find(".checkContact");
            if(c != undefined && !c.is(":checked")){
                jCC$(this).hide();
            }
        });
    }
    else{
        jCC$(".dataRow").show();
    }
});

In a pageBlock on the VF page I have:

Header block:

<apex:inputCheckbox id="HideContacts" label="Hide Unselected Contacts" styleClass="hideContacts" value="{!HideContacts}" />

Table block:

<apex:column styleclass="cc_col5" headerValue="CRMGroup">
    <apex:inputCheckbox title="{!contact.Id}" value="{!contact.IsSelected__c}" styleClass="checkContact"                                       onclick="updateDisplay(this, '{!contact.Id}');" />!contact.Contact__r.AccredoCRMGroup__c}
</apex:column>

In my Controller I have:

  public boolean HideContacts { get; set; }

1 Answer 1

1

If you want to control visibility individually using your controller, your public boolean HideContacts { get; set; } needs to be associated with a list of id's for the checkboxes. Each checkbox needs to have an id associated with it so your page will know which one to change the visibility settings or styleclass where visibility is hidden for that row.

I strongly suspect that an easier solution would be to connect your javascript to the controller using JS remoting methods and maintain the state in the controller. See the VisualForce Developer Guide for more on how to do this. There's an entire section devoted to JS remoting.

You must log in to answer this question.

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