You need to sign in to do that
Don't have an account?
Dennis Pyka
VF: Is it possible to show only selected rows in a datatable?
Hello Everyone,
I have a datatable based on the OpportunityLineItems Object that shows every Product in the Opportunity Record.
Now I want only the products to be shown that are selected by a checkbox.
Is there a possibility to render only specific rows in pure Visualforce? Something like <apex:DataTable renderrow="{!Oli.Checkbox == True}?
I only have a Professional licence, so Apex Code isnt available.
Is there a possibility to only do this in VF on clientside? Maybe JavaScript could also work..
Here is my Code:
I have a datatable based on the OpportunityLineItems Object that shows every Product in the Opportunity Record.
Now I want only the products to be shown that are selected by a checkbox.
Is there a possibility to render only specific rows in pure Visualforce? Something like <apex:DataTable renderrow="{!Oli.Checkbox == True}?
I only have a Professional licence, so Apex Code isnt available.
Is there a possibility to only do this in VF on clientside? Maybe JavaScript could also work..
Here is my Code:
<apex:variable var="index" value="{!1}"/> <apex:dataTable width="100%" value=" !Opportunity.OpportunityLineItems}" var="oli" <apex:column width="10%" headerClass="tableheaderleft" styleClass="tablebodycenter"> <apex:outputLabel value="{!index}."/> <apex:variable var="index" value="{!index+1}"/> <apex:facet name="header"></apex:facet> </apex:column> <apex:column width="40%" headerClass="tableheaderleft" styleClass="tablebodyleft"> <apex:facet name="header">Bezeichnung</apex:facet> <apex:OutputField value="{!oli.Name}"/> <br/> <table border="0" width="100%" style="border-collapse: collapse; margin-bottom:10px"> <tr><td width="30%" style="padding: 0px;line-height: 100%;"><strong>Leistungszeitraum:</strong> <br></br><apex:outputText value="{0, date, dd.MM.yyyy}"> <apex:param value="{!oli.ServiceDate}" /> </apex:outputText> - <apex:outputText value="{0, date, dd.MM.yyyy}"> <apex:param value="{!oli.Licensing_Period_Calculated__c}" /> </apex:outputText></td></tr> </table> </apex:column> <apex:column width="10%" headerClass="tableheadercenter" footerClass="tablefootercenter" styleClass="tablebodycenter"> <apex:facet name="header">Anzahl</apex:facet> <apex:OutputField value="{!oli.Quantity}"/> <apex:facet name="footer"></apex:facet> </apex:column> <apex:column width="20%" headerClass="tableheadercenter" styleClass="tablebodycenter"> <apex:facet name="header">Einzelbetrag</apex:facet> <apex:OutputField value="{!oli.UnitPrice}"/> <apex:facet name="footer"></apex:facet> </apex:column> <apex:column rendered="{!Opportunity.TotalDiscount__c != 0}" headerClass="tableheadercenter" footerClass="tablefootercenter" styleClass="tablebodycenter"> <apex:facet name="header">Rabatt</apex:facet> <apex:OutputField value="{!oli.Discount}"/> <apex:facet name="footer"></apex:facet> </apex:column> <apex:column width="20%" headerClass="tableheaderright" styleClass="tablebodyright"> <apex:facet name="header">Gesamtbetrag</apex:facet> <apex:OutputField value="{!oli.TotalPrice}"/> <apex:facet name="footer"></apex:facet> </apex:column> </apex:dataTable>
There is no such attribute like renderrow on the dataTable but you can use rendered attribute to control the visibility of any component within the data table. A small example is given below:
If the oli.checked is true than column elements will appear otherwise not. Let me know if you need any further help or information on this.
Thanks,
Abhishek Bansal.
many thanks for your fast reply! :)
I tried your solution, but it always throws this error: <apex:column> must be the direct child of either <apex:dataTable> or <apex:pageBlockTable>
This is the code: And to be as prezise as possible: I dont want the whole column to be hidden. If I have this list:
- Element 1 (with checkbox checked)
- Element 2 (with checkbox not checked)
- Element 3 (with checkbox checked)
Then I want the Datatable to output only 2 rows, one for Element 1 and one for Element 3. So the row for Element 2 should not be rendered.I think your solution would hide the whole column? Or do I understand something wrong?
Many thanks for your effort!
You can add the rendered attribute in each column of the table like this: In this way all the column in a row will be only displayed if this checkbox is true.
I think your solution would hide the whole column? Or do I understand something wrong?
Yes it will hide all the columns in a row which is exactly what you want.
Please add this condition in all the columns and then let me know if it worked for you or not.
Thanks,
Abhishek Bansal.
thanks again! :)
There seems to be a misunderstanding about columns and rows :D
I attached a screenshot to clarify that.
In this table I have the rows 1 and 2 and each of them shows a product, corresponding price and quantity in different columns. I do not want to hide the column price for example, instead I want to hide the row with number 2
This is what I am saying, add the rendered condtion on all the columns, in this way the entire row will be hidden when the checkbox is false.
Did you added the rendered condition on all the columns? Please add and try once. Let me know if you still need any further clarification on this.
You can also reach out to me directly on:
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
Thanks,
Abhishek Bansal.
I'm using this same solution on a VF page as well. I have OLI and I only want to show those with a field value of "NQP" so my columns each have rendered = hasNQP (proper format though! haha). It works SOMETIMES but not always. I often get PDF generation failed. Check the page markup is valid. The thing is there is always NQP so there is always something to be populated. As soon as I remove that datatable my form generates in PDF as expected with no problems.
I'm wondering if Dennis has run into this issue and found a solution or if either of you can suggest what I'm missing. Here is my datatable causing the problem: