0

I want to generate dynamic ID in my vf page for columns.

Here is my code:

<apex:repeat value="{!customerMap}" var="indexKey" >
    <apex:pageBlockTable value="{!customerMap[indexKey]}" var="objWrapper">
        <apex:column >  
            <apex:facet name="header">                           
                <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
            </apex:facet>
        <apex:inputCheckbox value="{!objWrapper.selected}" id="inputId"/>       
        </apex:column> 
        <apex:column value="{!objWrapper.custmer.name}" headerValue="{!indexKey}"/>  
    </apex:pageBlockTable> 
</apex:repeat>

I have a javascript which select all check boxes when i checked header check box.But here am Creating table with repeat tag,because of this whenever am clicking header check box it is selecting all the check boxes from all table. I want specific header check box for each table.

as per my knowledge this is because of Column ID which is Unique for all tables. am getting error literal value is required when i try to give dynamic ID.

can anyone pls help me on this,how to make id as dynamic.

Thanks

2

This would be helpful for you...

<apex:component >

    <script>
    function cvCheckAllOrNone(allOrNoneCheckbox) {

        // Find parent table
        var container = allOrNoneCheckbox;
        while (container.tagName != "TABLE") {
            container = container.parentNode;
        }

        // Switch all checkboxes
        var inputs = container.getElementsByTagName("input");
        var checked = allOrNoneCheckbox.checked;
        for (var i = 0; i < inputs.length; i++) { 
            var input = inputs.item(i);
            if (input.type == "checkbox") {
                if (input != allOrNoneCheckbox) {
                    input.checked = checked;
                }
            }
        }
    }
    </script>

    <apex:inputCheckbox onclick="cvCheckAllOrNone(this)" title="Toggle All Rows"/>

    </apex:component>

Use this component in column header and use it as master checkbox..

<apex:column >
    <apex:facet name="header">
        <c:CheckAllOrNone />
    </apex:facet>
    <apex:inputCheckbox value="{!mem.checked}"/>
</apex:column>

Refer from : master check box to select all records

0

Given that you want to select a group of checkboxes you shouldn't be using an ID anyway since an ID should be specific to a single element.

You could create your header checkbox like this:

<apex:inputCheckbox onclick="selectAllCheckboxes(this,'{!indexKey}')"/>

And then change the others to use class:

<apex:inputCheckbox value="{!objWrapper.selected}" styleClass="{!indexKey}"/>

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.