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.
b60b8f39ff477c8b6cc122ce62163fdf63aa25c1
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

We could take all of this out of the if sort_column_names block. If sort_column_names is an empty list, then the …

maubinmaubin
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. 
      
chipx86
maubin
  1. 
      
  2. djblets/datagrid/grids.py (Diff revision 2)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    We could take all of this out of the if sort_column_names block. If sort_column_names is an empty list, then the for loop won't run anyways.

  3. 
      
chipx86
Review request changed
Change Summary:

Moved some code out of an unnecessary conditional.

Commits:
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.
f6c5d3dbd37ba9d90a1a539942671dba6ae6829f
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.
b60b8f39ff477c8b6cc122ce62163fdf63aa25c1

Checks run (2 succeeded)

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