PhoenixKit.Users.TableColumns (phoenix_kit v1.5.1)

View Source

Table column configuration for user management dashboard.

Provides dynamic column selection including standard user fields and custom fields from the V17 custom fields system. Manages column metadata, ordering, and persistence through the settings system.

Summary

Functions

Checks if a column is required (cannot be hidden).

Gets all available column IDs from both standard and custom fields.

Gets all available columns for the user table.

Gets metadata for a specific column.

Gets the default column configuration.

Gets the current user table columns from settings.

Reorders columns based on user drag-and-drop interaction.

Updates the user table columns in settings.

Validates a list of column IDs against available columns.

Functions

column_required?(column_id)

Checks if a column is required (cannot be hidden).

Examples

iex> PhoenixKit.Users.TableColumns.column_required?("email")
true
iex> PhoenixKit.Users.TableColumns.column_required?("username")
false

get_all_available_column_ids()

Gets all available column IDs from both standard and custom fields.

get_available_columns()

Gets all available columns for the user table.

Returns a map combining standard columns with active custom fields. Each column includes metadata like label, field path, and rendering information.

Examples

iex> PhoenixKit.Users.TableColumns.get_available_columns()
%{
  "email" => %{label: "Email", field: "email", required: true},
  "username" => %{label: "Username", field: "username", required: false},
  "custom_123" => %{label: "Department", field: "custom_data.department", field_id: 123, field_type: "select", required: false}
}

get_column_metadata(column_id)

Gets metadata for a specific column.

Examples

iex> PhoenixKit.Users.TableColumns.get_column_metadata("email")
%{label: "Email", field: "email", required: true}

get_default_columns()

Gets the default column configuration.

Returns the list of columns that should be visible by default if no user preference is saved in settings.

get_user_table_columns()

Gets the current user table columns from settings.

Returns the user's saved column preference, or the default configuration if no preference is saved.

Examples

iex> PhoenixKit.Users.TableColumns.get_user_table_columns()
["email", "username", "role", "status", "registered"]

reorder_columns(new_order, current_selected)

Reorders columns based on user drag-and-drop interaction.

Takes the new order from the frontend and ensures it's valid and complete. Actions column is always appended at the end.

Examples

iex> PhoenixKit.Users.TableColumns.reorder_columns(["username", "email"], ["email", "username", "actions"])
["username", "email", "actions"]

update_user_table_columns(columns)

Updates the user table columns in settings.

Saves the user's column preference to the settings table for persistence across page reloads and sessions.

Examples

iex> PhoenixKit.Users.TableColumns.update_user_table_columns(["email", "role", "status"])
{:ok, %Setting{}}

validate_columns(column_ids)

Validates a list of column IDs against available columns.

Returns only the valid column IDs from the input list.

Examples

iex> PhoenixKit.Users.TableColumns.validate_columns(["email", "invalid_id", "role"])
["email", "role"]