Add constructor-level customization of columns and sorting in datagrids.

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

Information

Djblets
release-5.x

Reviewers

Datagrids have historically allowed for custom column selection/ordering
and sorting via HTTP GET query strings. This works great in the case
where you want to display a standard datagrid page with user choices,
but less so when you want to handle providing these options through
other means.

This change introduces new columns and sort arguments to the
DataGrid constructor. These both take lists of strings, and behave the
same way that the query string versions do. They can also take None,
which will force usage of the datagrid defaults.

This not only overrides (and disables) anything in the querystring, but
also prevents both loading from and saving to the user profile.

Unit tests pass.

Tested with some in-progress code using specially-constructed datagrids,
and verified I could define the columns and sort order.

Summary ID
Add constructor-level customization of columns and sorting in datagrids.
Datagrids have historically allowed for custom column selection/ordering and sorting via HTTP GET query strings. This works great in the case where you want to display a standard datagrid page with user choices, but less so when you want to handle providing these options through other means. This change introduces new `columns` and `sort` arguments to the `DataGrid` constructor. These both take lists of strings, and behave the same way that the query string versions do. They can also take `None`, which will force usage of the datagrid defaults. This not only overrides (and disables) anything in the querystring, but also prevents both loading from and saving to the user profile.
a077d3ae3d5ccae704ea497cbb461dca45cb540e
Description From Last Updated

In the change description, you say a None value forces usage of the datagrid defaults. Can we add unit tests …

daviddavid

These were wrong previously, but both should be typed as str | None.

daviddavid

Since you removed the part of the docstring about returning bool, can we update this to just return list[str]?

daviddavid
Checks run (2 succeeded)
flake8 passed.
JSHint passed.
david
  1. 
      
  2. Show all issues

    In the change description, you say a None value forces usage of the datagrid defaults. Can we add unit tests for this?

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

    These were wrong previously, but both should be typed as str | None.

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

    Since you removed the part of the docstring about returning bool, can we update this to just return list[str]?

  5.