If there is a requirement where a column in a table should be hid based on a condition then the below approach is one of the solutions.
In the above picture, the third column (Hide on Condition) gets hidden at run time when a condition is met. Following below steps will achieve that result.
- Create a table and for the column to be hidden, provide a data-tour-id as ‘hide-col’ for both header and data cell.
2. Create a HTML fragment rule(Rule-HTML-Fragment) called HideTableColumn and insert below code.
3. Create another HTML fragment rule(Rule-HTML-Fragment) called HideTableColumnConditionally and insert below code.
4. Include HideTableColumnConditionally fragment rule in the table header (one of the cells) using pega:include jsp tag.
<pega:include name=”HideTableColumnConditionally” type=”Rule-HTML-Fragment”/>
5. Make sure the when condition rule is in a class that is in inheritance hierarchy.
6. Because the main fragment rule is inserted in table header cell, it applies to all pages (if there is pagination).
7. Test it out and make changes as per your application use case.
Be vigilant to use this approach if there is huge result set (over 10000 records) in single page. Also, change When condition and other rule names accordingly to your application standards.
Let me know if this approach worked for your use case and appreciate if you post any other approaches to hide column conditionally.