Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackkatz/81978724e6052f760a381cd0af4f8c1d to your computer and use it in GitHub Desktop.
Save zackkatz/81978724e6052f760a381cd0af4f8c1d to your computer and use it in GitHub Desktop.
GravityView DataTables - Override cell output based on values
<?php
/**
* This is an example of modifying the appearance of a cell in DataTables based on the value.
*
* DO NOT USE THIS CODE WITHOUT MODIFICATION.
*
* @license https://www.gnu.org/licenses/gpl-2.0.html GPLv2 or later
*
* @param array $row The entry row HTML to be rendered in DataTables.
* @param \GV\View $view The current View being rendered. Not used in this example.
* @param \GV\GF_Entry $entry The GravityView Entry object representing the Gravity Forms entry. Use $entry->as_entry() to get the GF array. Not used in this example.
*/
add_filter( 'gravityview/datatables/output/entry', function( $row, $view, $entry ) {
// UPDATE THIS ID!
// This is the index on the front-end (starting with zero) of the field you want to modify.
// For example, the value 3 will be modifying the fourth table column being displayed.
$column_index = 3;
$column_value = rgar( $row, $column_index );
// THIS IS PLACEHOLDER LOGIC!
// This is an example of not modifying how the field is displayed. In this case, if the value is less than 10, don't change its appearance.
if ( $column_value < 10 ) {
return $row; // Return early to not change the formatting for this field
}
// THIS IS AN EXAMPLE MODIFICATION!
// Here, we're making the text blue if it's equal to or greater than 10.
$column_value = sprintf( '<span style="color:blue;">%s</span>', $column_value );
// Override the previous value.
$row[ $column_index ] = $column_value;
return $row;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment