Problem: I have a table-style View that displays several columns of custom field values. I would like to use a conditional that hides the value in a specific column if the value is identical to the same column in a previous row.
Solution: When the loop is rendered, each iteration has no reference to a previous or future iteration. That means it's not possible to set up a conditional that compares a value from one iteration to a value in another iteration. Instead, you would have to do this with custom CSS and JavaScript. For example, add a custom class to each system-cf cell, and a wrapper span tag like this:
<td class="only-first-system-cf"><span>[wpv-post-field name="wpcf-system-cf"]</span></td>
Then in your custom CSS:
.only-first-system-cf > span { display:none; } .only-first-system-cf.first > span { display:inline; }
Then in your custom JS:
jQuery(document).ready(function(){ var firsts = []; var txt = ''; jQuery('.only-first-system-cf').each(function(index, item) { txt = jQuery(item).text(); if(firsts.indexOf(txt) == -1){ firsts.push(txt); jQuery(item).addClass('first'); } }); });
Relevant Documentation:
https://toolset.com/documentation/user-guides/digging-into-view-outputs/
https://toolset.com/documentation/user-guides/adding-custom-css-views/
https://toolset.com/documentation/user-guides/adding-custom-javascript-views/
https://api.jquery.com/jquery.each/
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 3 months ago.
Assisted by: Christian Cox.