Skip to content
🚀 Rapid Application Development with the App Builder

render

The render hook allows developers to implement custom renderers for specific table columns. This powerful hook enables rendering based on other column values or external data fetched via AJAX. It also supports built-in functions to change the text color and background color of other columns of the same rows.

Parameters

ParameterTypeDescription
columnNamestringColumn name of column being rendered.
originalValueanyColumn value as stored in the database.
renderedValueanyColumn value after default rendering.
rowobjectObject containing the original values of all columns.

Structure parameter row

js
row: {
	column_1: value_ column_1,
	column_2: value_column_2,
	column_n: value_column_n,
}

Return Value

TypeDescription
stringAn HTML string, typically created using a template literal.
HTMLElementA DOM element node created with vanilla JavaScript.
jQueryA jQuery object wrapping the new element.

Additional Built-In Functions

Parameter columnName is optional. If omitted the column name of the rendered column is used.

setColor(color, columnName)
setBackgroundColor(color, columnName)
setRowColor(color)
setRowBackgroundColor(color)

✨ Basic Example

Example represents the default behaviour.

js
((columnName, originalValue, renderedValue, row) => {
	return renderValue
})

✨ Adding Content and Styles

Using a Font Awesome icons.

js
((columnName, originalValue, renderedValue, row) => {
	return `<span>
		<i class="fa-solid fa-check"></i>
		${renderedValue}
	</span>`
})

✨ Accessing other Column Values

js
((columnName, originalValue, renderedValue, row) => {
	if (row.status === "check" && row.balance < 0) {
		return `<div style="color: red">
			<i class="fa-solid fa-check"></i>
			${renderedValue}
		</div>`
	}

	return renderedValue
})

✨ Combining Multiple Features

js
((columnName, originalValue, renderedValue, row) => {
	if (row.city === "Amsterdam") {
		// Change row color and background color
		setRowColor("white")
		setRowBackgroundColor("orange")

		// Change column color and background color
		setColor("blue")
		setBackgroundColor("yellow")

		// Change color and background color of column customerName
		setColor("black", "customerName")
		setBackgroundColor("white", "customerName")

		return `<strong>
			${renderedValue}
		</strong>`
	} else {
		// Don't forget to reset the column color and background color
		// Row color and background color will reset automatically
		setColor("initial", "customerName")
		setBackgroundColor("initial", "customerName")

		return renderedValue
	}
})

Other Examples

Notes

  • Do not manipulate the DOM directly from a hook. WP Data Access is state-based, and all (re)rendering is performed through state changes. Manipulating the DOM from a hook might crash an app. Use built-in functions to change the app state or return an element that meets your requirements.
  • Column renderers are not available for computed fields, aggregations, inline editing, lookups, and WordPress media.
  • When built-in functions are used to overwrite color or background color in multiple places, the last assignment takes precedence.
  • It is not possible to change the color or background color of other rows.