Add hidden_from_list field attribute - #756
Open
Alwinator wants to merge 2 commits into
Open
Conversation
Alwinator
force-pushed
the
add_hidden_from_list_option
branch
from
April 30, 2026 11:17
5957adb to
e9dbe47
Compare
Alwinator
force-pushed
the
add_hidden_from_list_option
branch
from
April 30, 2026 11:19
e9dbe47 to
7110072
Compare
hidden_from_list field attributehidden_from_list field attribute
hidden_from_list field attributehidden_from_list field attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
hidden_from_listattribute toBaseFieldthat allows hiding columns from the list view by default while still keeping them accessible via DataTables' Column Visibility button.Motivation
Currently, the only way to remove a column from the list view is
exclude_from_list, which completely removes the column from the DataTable — it cannot be toggled back by the user, and it is no longer available for filtering or searching.There are cases where a field contains useful but non-essential information (e.g. long descriptions, internal IDs, timestamps) that should be hidden by default to reduce clutter, but still available for users who want to see it. Additionally, hidden fields can still be used for filtering and searching via Search Builder, which is valuable when users need to query on columns they don't need to see in every row.
hidden_from_listfills this gap: the column is rendered in the DataTable withvisible: falseviacolumnDefs, so users can reveal it using the Column Visibility button (enabled by default viacolumn_visibility = True), and the column remains available for filtering and sorting.Changes
starlette_admin/fields.pyhidden_from_list: Optional[bool] = Falseattribute toBaseFielddataclass.starlette_admin/views.pyself.datatables_optionsin_configs()with a call to the new_merged_datatables_options()method._merged_datatables_options(request)which deep-copies user-defineddatatables_options, detects fields withhidden_from_list=True, and appends acolumnDefsentry with{"visible": False, "targets": [...]}(offset by +1 to account for the leading checkbox column).tests/test_base_model_view.pytest_hidden_from_list_field_attribute— verifies the attribute defaults toFalseand can be set toTrue.test_hidden_from_list_still_in_field_list— confirms hidden fields are still included inget_fields_list(unlikeexclude_from_list).test_hidden_from_list_excluded_field_not_in_list— confirms thatexclude_from_list=Truetakes precedence and removes the field entirely.test_merged_datatables_options_hidden_columns— verifies correctcolumnDefstargets are generated for multiple hidden fields.test_merged_datatables_options_no_hidden— verifies nocolumnDefsare injected when there are no hidden fields.test_merged_datatables_options_preserves_user_options— verifies existingdatatables_optionskeys are preserved.test_merged_datatables_options_merges_existing_column_defs— verifies the hidden column def is appended (not overwritten) when the user already hascolumnDefs.Usage
Backwards Compatibility
Fully backwards-compatible.
hidden_from_listdefaults toFalse, so existing views are unaffected. User-defineddatatables_options(including existingcolumnDefs) are preserved and merged.