+ Start a Discussion

Flexible filtering inside each row in a pageBlockTabl component

Hi SF developers,


I've faced with one interesting issue which I can't manage by myself.


Please imagine the situation when you have an custom object with custom fields "Type__c" as a picklist and custom field "Contact__c" as a lookup on Contacts. Standard SF' Contact object in turn has it's custom field named "Type__c". I've done simple lookup filter for Contact__c field for my superior custom object - [superior object] Contact Type equals Contact: Type.


Going further.


I have VF page.

<apex:pageBlockTable value="{!superiorObjects}" var="so" >
                  <apex:column >
                      <apex:facet name="header"><b>Contact Type</b></apex:facet>
                      <apex:inputField value="{!so.Contact_Type__c}" />
                  <apex:column >
                      <apex:facet name="header"><b>Contact Name</b></apex:facet>
                      <apex:inputField value="{!so.Contact__c}" styleClass="contactName"/>


It works fantastic. It filters contacts by selected type. It is great.

BUT. Imagine next steps:

1) select type A;

2) select contact;

3) change type to B.


And after this I have a question: how to clear contact name automatically? User can do it manually. Neither by selecting input field and clear text in it or by opening lookup window and clear filter there. It will work fine. But is there a way to do it automatically?


If it was not a table I would use an <apex:actionSupport> component. But I don't know how to use it for the table. I can't set id for each inputField in each row for Contact name column and tell actionSupport to clear specific id when change the value in type combo box.


Can someone advise me some solution for automatic clear in the <apex:pageBlockTable>?


You should be able to use an actionsupport and an enclosed apex:param that contains the id of the contact.  Then the controller can decide whether to remove the contact from the list depending on what has change, and if you rerender the pageblocktable the contact will simply disappear.


Here's a blog post that should help to get you started:




I have no ID at that moment. I haven't got any field just empty object.

I'm creating new object. Insert empty raw with empty object and setting values for every field which I need. In the backend I have only empty object. To be more precise I have list of empty objects.


The following blog post explains how to manage a list of new objects - does this help: