diff --git a/datasette/views/table_extras.py b/datasette/views/table_extras.py
index 0eefeaa9..b6e653c4 100644
--- a/datasette/views/table_extras.py
+++ b/datasette/views/table_extras.py
@@ -395,11 +395,21 @@ class DisplayRowsExtra(Extra):
class RenderCellExtra(Extra):
description = "Rendered HTML for each cell using the render_cell plugin hook"
example = ExtraExample(
- value=[
- {},
- {"content": "Custom rendered HTML"},
- ],
- note="Only columns whose rendered value differs from the default are included.",
+ value={
+ "rows": [
+ {"id": 1, "content": "hello"},
+ {"id": 4, "content": "RENDER_CELL_DEMO"},
+ ],
+ "render_cell": [
+ {},
+ {"content": "Custom rendered HTML"},
+ ],
+ },
+ note=(
+ "The ``render_cell`` array has one item per row, in the same order as "
+ "the ``rows`` array. Each object is keyed by column name. Only columns "
+ "whose rendered value differs from the default are included."
+ ),
)
scopes = frozenset({ExtraScope.TABLE})
diff --git a/docs/json_api.rst b/docs/json_api.rst
index d12a388e..24d59577 100644
--- a/docs/json_api.rst
+++ b/docs/json_api.rst
@@ -428,16 +428,28 @@ The available table extras are listed below.
``render_cell``
Rendered HTML for each cell using the render_cell plugin hook
- Only columns whose rendered value differs from the default are included.
+ The ``render_cell`` array has one item per row, in the same order as the ``rows`` array. Each object is keyed by column name. Only columns whose rendered value differs from the default are included.
.. code-block:: json
- [
- {},
- {
- "content": "Custom rendered HTML"
- }
- ]
+ {
+ "rows": [
+ {
+ "id": 1,
+ "content": "hello"
+ },
+ {
+ "id": 4,
+ "content": "RENDER_CELL_DEMO"
+ }
+ ],
+ "render_cell": [
+ {},
+ {
+ "content": "Custom rendered HTML"
+ }
+ ]
+ }
``debug``
Extra debug information
diff --git a/tests/test_docs.py b/tests/test_docs.py
index 784755e9..c4e0a849 100644
--- a/tests/test_docs.py
+++ b/tests/test_docs.py
@@ -122,6 +122,14 @@ def test_table_extra_examples_are_documented():
assert ".. code-block:: json" in section
+def test_render_cell_extra_example_explains_row_and_column_mapping():
+ content = (docs_path / "json_api.rst").read_text()
+ section = content.split("``render_cell``")[-1].split("``query``")[0]
+ assert "same order as the ``rows`` array" in section
+ assert '"rows": [' in section
+ assert '"render_cell": [' in section
+
+
@pytest.fixture(scope="session")
def documented_labels():
labels = set()