[SalesForce] Select and edit wrapper rows in pageBlockTable using Javascript

I have a custom visualforce page that displays a list of records in an apex pageblocktable, and have input fields in the cells to change field values of the records. I also have a column of checkboxes to select records from the table( https://developer.salesforce.com/page/Wrapper_Class)

I want to select some records, and when I change one field value of a selected record, then that field of all the other selected records should also reflect that change. Is there a way to do this only on the client side with javascript?

eg: There are 10 records (rows) in the pageblocktable and each record has 3 fields(columns), Name, age and salary. If I select 5 rows (using the checkbox), and change the salary of one row to 50000, then all 5 selected rows should show a salary of 50000.

Best Answer

It can be done using client side javascript. To get exact Id of the element, you can use "Inspect Element" option in chrome. Basically salesforce will add the entire path of parent apex elements in the ID of child element. For example check sample code below,

<apex:page id="page">
    <apex:form id="form">
        <apex:pageblockTable id="table">
            <apex:inputField value="{!testvalue}" id="field"/>
        </apex:pageblockTable>
    </apex:form>
</apex:page>

It will result in final Id of the field as

page:form:table:field

instead of simple "field". If you are using rerender on the field using apex tags, you can directly use Id "field". But if you are using javascript, you need to use the full ID, which is the actual Id.

Related Topic