Add JSON serialization of datagrids.

Review Request #14819 — Created Feb. 16, 2026 and updated

Information

Djblets
release-5.x

Reviewers

Datagrids can now be serialized to JSON, providing information on active
and available columns, pagination, sorting information, rows, and each
cell within. The cells contain both rendered HTML (the <td> and
everything inside) and a JSON value for processing.

This can be used to provide datagrid functionality in other contexts.
The primary purpose at this time is to enable API access to datagrids.
The information can be returned as-is or further processed to provide
a more integrated response into an API response format.

Columns can provide an explicit JSON value alongside rendered HTML. Both
now default to making use of a new get_raw_object_value(), which can
provide a suitable value from an object. This is intended for column
implementations to override and use as necessary, and to simplify common
code used for render_data() and to_json().

Unit tests pass.

Summary ID
Add JSON serialization of datagrids.
Datagrids can now be serialized to JSON, providing information on active and available columns, pagination, sorting information, rows, and each cell within. The cells contain both rendered HTML (the `<td>` and everything inside) and a JSON value for processing. This can be used to provide datagrid functionality in other contexts. The primary purpose at this time is to enable API access to datagrids. The information can be returned as-is or further processed to provide a more integrated response into an API response format. Columns can provide an explicit JSON value alongside rendered HTML. Both now default to making use of a new `get_raw_object_value()`, which can provide a suitable value from an object. This is intended for column implementations to override and use as necessary, and to simplify common code used for `render_data()` and `to_json()`.
11740c0c81165439a08fa74dd2a505c34a7efab0
Description From Last Updated

Should probably be "... in a datagrid." instead of "... in a datagrid row."

daviddavid

Can we add "or None if this column has no field_name." here too.

maubinmaubin

Given that this implementation types the return value as datetime | None, seems like this could say it returns datetime.datetime.

daviddavid

Other implementations of this use "Return a JSON-serializable value for an object in a cell" for the description. Looks like …

daviddavid

Shouldn't this be using self.get_raw_object_value(obj)? Let's also call the variable something other than datetime so we don't shadow the import.

daviddavid

You can use stateful_columns here instead of self.columns.

maubinmaubin

Please fix the docstring to say "... with no field name"

daviddavid
david
  1. 
      
  2. djblets/datagrid/grids.py (Diff revision 1)
     
     
    Show all issues

    Should probably be "... in a datagrid." instead of "... in a datagrid row."

  3. djblets/datagrid/grids.py (Diff revision 1)
     
     
    Show all issues

    Given that this implementation types the return value as datetime | None, seems like this could say it returns datetime.datetime.

    1. Yeah, copy-paste-o's.

  4. djblets/datagrid/grids.py (Diff revision 1)
     
     
    Show all issues

    Other implementations of this use "Return a JSON-serializable value for an object in a cell" for the description. Looks like this was missed as you iterated.

  5. djblets/datagrid/grids.py (Diff revision 1)
     
     
    Show all issues

    Shouldn't this be using self.get_raw_object_value(obj)?

    Let's also call the variable something other than datetime so we don't shadow the import.

  6. djblets/datagrid/tests.py (Diff revision 1)
     
     
     
    Show all issues

    Please fix the docstring to say "... with no field name"

  7. 
      
maubin
  1. 
      
  2. djblets/datagrid/grids.py (Diff revision 1)
     
     
    Show all issues

    Can we add "or None if this column has no field_name." here too.

  3. djblets/datagrid/grids.py (Diff revision 1)
     
     
    Show all issues

    You can use stateful_columns here instead of self.columns.

  4. 
      
chipx86
Review request changed
Change Summary:
  • Fixed a handful of docs and docstrings.
  • Updated DateTimeSinceColumn to utilize get_raw_object_value(), and fixed a variable name conflict.
  • Updated a reference to self.columns to just use the local variable we already pulled out.
Commits:
Summary ID
Add JSON serialization of datagrids.
Datagrids can now be serialized to JSON, providing information on active and available columns, pagination, sorting information, rows, and each cell within. The cells contain both rendered HTML (the `<td>` and everything inside) and a JSON value for processing. This can be used to provide datagrid functionality in other contexts. The primary purpose at this time is to enable API access to datagrids. The information can be returned as-is or further processed to provide a more integrated response into an API response format. Columns can provide an explicit JSON value alongside rendered HTML. Both now default to making use of a new `get_raw_object_value()`, which can provide a suitable value from an object. This is intended for column implementations to override and use as necessary, and to simplify common code used for `render_data()` and `to_json()`.
3fbcb7f5fd9f71ed1c49e2acb314f30950c8121b
Add JSON serialization of datagrids.
Datagrids can now be serialized to JSON, providing information on active and available columns, pagination, sorting information, rows, and each cell within. The cells contain both rendered HTML (the `<td>` and everything inside) and a JSON value for processing. This can be used to provide datagrid functionality in other contexts. The primary purpose at this time is to enable API access to datagrids. The information can be returned as-is or further processed to provide a more integrated response into an API response format. Columns can provide an explicit JSON value alongside rendered HTML. Both now default to making use of a new `get_raw_object_value()`, which can provide a suitable value from an object. This is intended for column implementations to override and use as necessary, and to simplify common code used for `render_data()` and `to_json()`.
11740c0c81165439a08fa74dd2a505c34a7efab0

Checks run (2 succeeded)

flake8 passed.
JSHint passed.
maubin
  1. Ship It!
  2. 
      
david
  1. Ship It!
  2.