2

I implemented a checkbox class with a checkaLL function(called using javascript) which makes sure to select All checkboxes as it should. However, the problem is that it doesn't visually show the checkboxes as being selected. Aka the checkboxes themselves should have a check mark on it.

Here is the relevant code for that section:

<script type = "text/javascript">
    function checkAllBoxes()
    {
        callCheckAllBoxes(); 
    }
</script>

Here is the visualforce code that calls the javascript function:

    <apex:form>
      <apex:pageBlock>
        <apex:dataTable>
          <apex:column >
            <apex:facet name="header">
              <apex:inputCheckbox onclick="checkAllBoxes(this)"> </apex:inputCheckbox>
            </apex:facet>
            <apex:inputCheckbox value="{!a.selected}" id="checkedone"/> 
          </apex:column>
        </apex:dataTable>
      </apex:pageBlock>
      <apex:actionFunction name="callCheckAllBoxes" action="{!checkAll}" reRender="a.Selected"/>
    </apex:form>

and this is what the checkAll function from my controller looks like:

    public void checkAll()
    {
System.debug('entered checkAll');
        for(assetsWrapper checkAssets: assetsList)
            checkAssets.selected = true; 
        isrendered = false;
system.debug('exited checkAll');
    }

I know that the functionality of the method works because all the checkboxes get selected(I tested this separately) but it won't visually show the checkboxes as being ticked. Any ideas?

I can't do a page refresh either because it would run the constructor again thus repopulating the list that the checkboxes are attached to (aka create duplicate lists below each other).

Is there a way to just refresh the checkbox column/the dataTable itself?

3

It looks like you just need to change your isrendered to True in your controller method, and reRender = "checkedone" in your visual force page. That should refresh your checkbox column.

Edit of your controller method:

public void checkAll()
    {
System.debug('entered checkAll');
        for(assetsWrapper checkAssets: assetsList)
            checkAssets.selected = true; 
        isrendered = false;
system.debug('exited checkAll');
    }

Edit of your visualforce page:

<apex:form>
  <apex:pageBlock>
    <apex:dataTable>
      <apex:column >
        <apex:facet name="header">
          <apex:inputCheckbox onclick="checkAllBoxes(this)"> </apex:inputCheckbox>
        </apex:facet>
        <apex:inputCheckbox value="{!a.selected}" id="checkedone"/> 
      </apex:column>
    </apex:dataTable>
  </apex:pageBlock>
  <apex:actionFunction name="callCheckAllBoxes" action="{!checkAll}" reRender="a.Selected"/>
</apex:form>

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.