How to Highlight Rows and Cells in TablePress Based on Content
Content
Highlighting specific rows or cells in your TablePress tables is a powerful way to draw attention to important information. Whether you want to color-code status updates, emphasize key data, or improve visual organization, this guide covers the most common methods to achieve this.
Why Highlighting is Useful
Visual cues like colored rows or cells help users quickly scan and interpret data. Common use cases include:
- Showing a status (e.g., Open, Closed, Pending).
- Highlighting rows that contain a specific keyword.
- Emphasizing cells with important values like percentages or decimals.
- Making entire rows clickable if they contain a link.
Method 1: Using the Row Highlighting Shortcode Parameter
For basic row highlighting based on text content, you can use the row_highlight shortcode parameter. This is a built-in feature of TablePress.
Shortcode Example:
[table id=123 row_highlight="Open||Closed" /]
Key Points:
- Use two vertical bars
||to separate multiple terms, not a comma. - The plugin will search the entire row for the specified text.
- By default, a CSS class like
.highlight-1is added to matching rows, which you can then style.
Example CSS:
.tablepress .highlight-1 {
background-color: #d4ffd4 !important; /* Light green */
}
Method 2: Manual Cell Highlighting with Custom CSS
To highlight individual cells, you can manually add a CSS class directly to a cell's content using the Advanced Editor.
Step-by-Step:
- Edit your table.
- Click on the cell you want to highlight to open the editor.
- Switch to the "Text" tab (HTML view).
- Wrap your cell content in a span with a custom class. For example:
<span class="highlight-red">Closed</span> - Add your custom CSS to the "Custom CSS" box in TablePress's Plugin Options.
Example CSS:
.highlight-red {
background-color: #ffdddd;
font-weight: bold;
color: #ff0000;
}
.highlight-green {
background-color: #ddffdd;
font-weight: bold;
color: #008000;
}
Method 3: Using JavaScript for Dynamic Highlighting
For more advanced control, such as highlighting rows that contain a link or adding a pointer cursor, you can use JavaScript/jQuery.
Example: Highlight and Style Clickable Rows
This code adds a CSS class to any row that contains a link, making it appear clickable.
jQuery(document).ready(function($){
$('.tablepress-id-1 tr').each(function() {
if ( $(this).find('a').length ) {
$(this).addClass('has-link');
}
});
});
Corresponding CSS:
.tablepress-id-1 tr.has-link {
background-color: #e6f7ff !important; /* Light blue background */
cursor: pointer !important; /* Change cursor to a hand */
}
Remember to change the .tablepress-id-1 selector to match your specific table's ID.
Common Issues and Troubleshooting
- Specificity Problems: If your CSS isn't applying, your selector may not be specific enough. Use more specific selectors like
.tablepress-id-3 .row-4 tdand use the!importantrule if necessary. - Special Characters: Highlighting values with decimals (0.0) or symbols (100%) can sometimes be tricky. Ensure your CSS classes are named correctly and match the value exactly.
- Multiple Columns: The free version's
highlight_columnsparameter typically only supports one column. To highlight multiple specific columns, you would need to use custom CSS targeting each column, for example:.tablepress-id-5 .column-2, .tablepress-id-5 .column-4, .tablepress-id-5 .column-7.
When to Consider Premium Features
Based on the sample threads, the TablePress team's premium modules offer more advanced functionality for complex scenarios, such as:
- The Row Filtering module for highlighting based on text in a specific column.
- The Cell Highlighting module for automatically coloring cells based on their dynamic values (e.g., turning a cell red if it contains "Closed").
For assistance with these premium features, users are typically directed to contact support via the email address found on the "About" screen within the TablePress Pro plugin on their site, as per the WordPress.org forum guidelines.
By combining these shortcode parameters, CSS, and JavaScript techniques, you can effectively highlight and style your TablePress tables to meet a wide variety of design and functional needs.
Related Support Threads Support
-
Additional information sub-row with clickhttps://wordpress.org/support/topic/additional-information-sub-row-with-click/
-
Récupérer les données d’une ligne en sélectionnant le texte d’une cellulehttps://wordpress.org/support/topic/recuperer-les-donnees-dune-ligne-en-selectionnant-le-texte-dune-cellule/
-
Product Comparison Tablehttps://wordpress.org/support/topic/product-comparison-table/
-
How do you make a single cell active for visitors?https://wordpress.org/support/topic/how-do-you-make-a-single-cell-active-for-visitors/
-
tag ” three dotshttps://wordpress.org/support/topic/tag-three-dots/
-
Clickable phone number in columnhttps://wordpress.org/support/topic/clickable-phone-number-in-column/
-
Star rating & other featureshttps://wordpress.org/support/topic/star-rating-other-features/
-
Assign Cells to New Classhttps://wordpress.org/support/topic/assign-cells-to-new-class/
-
Custom CSS for highlighting cell based on texthttps://wordpress.org/support/topic/custom-css-for-highlighting-cell-based-on-text/
-
Cell value as a clickable search keyhttps://wordpress.org/support/topic/cell-value-as-a-clickable-search-key-2/
-
Frondend Cell Editinghttps://wordpress.org/support/topic/frondend-cell-editing/
-
Tablepress Cell Highlightinghttps://wordpress.org/support/topic/tablepress-cell-highlighting/
-
Hover to highlight single cellhttps://wordpress.org/support/topic/hover-to-highlight-single-cell/
-
Row Highlighting By Contenthttps://wordpress.org/support/topic/row-highlighting-by-content/
-
Masking In columnhttps://wordpress.org/support/topic/masking-in-column/
-
How to display the value of one cell based on the value of anotherhttps://wordpress.org/support/topic/how-to-display-the-value-of-one-cell-based-on-the-value-of-another/
-
aria-labelledby – RGAAhttps://wordpress.org/support/topic/aria-labelledby-rgaa/
-
Count row with same infohttps://wordpress.org/support/topic/count-row-with-same-info/
-
Color setting at Advanced Editorhttps://wordpress.org/support/topic/color-setting-at-advanced-editor/
-
Highlight row on clickhttps://wordpress.org/support/topic/highlight-row-on-click/
-
Single Cell Font Familyhttps://wordpress.org/support/topic/single-cell-font-family/
-
Tablepress highlights problemhttps://wordpress.org/support/topic/tablepress-highlights-problem/
-
Single Cell by valuehttps://wordpress.org/support/topic/single-cell-by-value/
-
Use two terms in row_highlight?https://wordpress.org/support/topic/use-two-terms-in-row_highlight/
-
make a row clickablehttps://wordpress.org/support/topic/make-a-row-clickable/
-
Editor: Custom Keyboard Shortcutshttps://wordpress.org/support/topic/editor-custom-keyboard-shortcuts/
-
Print from rowshttps://wordpress.org/support/topic/print-from-rows/
-
Only special users can see hidden rows?https://wordpress.org/support/topic/only-special-users-can-see-hidden-rows/
-
Highlight a CELL Based on Value?https://wordpress.org/support/topic/highlight-a-cell-based-on-value/
-
Question regarding Pro version before I buyhttps://wordpress.org/support/topic/question-regarding-pro-version-before-i-buy/
-
How to highlight columns when hovering on them in tablehttps://wordpress.org/support/topic/how-to-highlight-columns-when-hovering-on-them-in-table/
-
colspan from css without entering #colspan# into the fieldshttps://wordpress.org/support/topic/colspan-from-css-without-entering-colspan-into-the-fields/
-
color specific multiple cellshttps://wordpress.org/support/topic/color-specific-multiple-cells/
-
birthday of the dayhttps://wordpress.org/support/topic/birthday-of-the-day/