Skip to main content

fret_ui_headless/table/
options.rs

1use super::{ColumnResizeDirection, ColumnResizeMode, GroupedColumnMode};
2
3/// Headless table options (TanStack-aligned semantics, Rust-native API).
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct TableOptions {
6    /// Enables/disables pinning features globally (TanStack `enablePinning`).
7    pub enable_pinning: bool,
8    /// If enabled, filtering is assumed to be done externally (e.g. server-side).
9    ///
10    /// When `true`, `filtered_row_model()` returns `pre_filtered_row_model()`.
11    pub manual_filtering: bool,
12    /// Enables/disables all filtering features (TanStack `enableFilters`).
13    pub enable_filters: bool,
14    /// Enables/disables per-column filtering (TanStack `enableColumnFilters`).
15    pub enable_column_filters: bool,
16    /// Enables/disables global filtering (TanStack `enableGlobalFilter`).
17    pub enable_global_filter: bool,
18    /// Filter children first and bubble matches to parents (TanStack `filterFromLeafRows`).
19    pub filter_from_leaf_rows: bool,
20    /// Maximum depth to apply leaf-row filtering recursion (TanStack `maxLeafRowFilterDepth`).
21    pub max_leaf_row_filter_depth: usize,
22    /// If enabled, sorting is assumed to be done externally (e.g. server-side).
23    ///
24    /// When `true`, `sorted_row_model()` returns `pre_sorted_row_model()`.
25    pub manual_sorting: bool,
26    /// If enabled, pagination is assumed to be done externally (e.g. server-side).
27    ///
28    /// When `true`, `row_model()` returns `pre_pagination_row_model()`.
29    pub manual_pagination: bool,
30    /// TanStack-aligned: pagination auto reset gate (`autoResetPageIndex`).
31    pub auto_reset_page_index: Option<bool>,
32    /// TanStack-aligned: total page count hint (`pageCount`).
33    ///
34    /// When set to `-1`, the page count is treated as unknown.
35    pub page_count: Option<i32>,
36    /// TanStack-aligned: total row count hint (`rowCount`).
37    pub row_count: Option<usize>,
38    /// If enabled, expanded row handling is assumed to be done externally.
39    ///
40    /// When `true`, `expanded_row_model()` returns `pre_expanded_row_model()`.
41    pub manual_expanding: bool,
42    /// Enables/disables expanding for all rows (TanStack `enableExpanding`).
43    pub enable_expanding: bool,
44    /// TanStack-aligned: global auto reset gate (`autoResetAll`).
45    pub auto_reset_all: Option<bool>,
46    /// TanStack-aligned: expanded auto reset gate (`autoResetExpanded`).
47    pub auto_reset_expanded: Option<bool>,
48    /// When true, pagination counts expanded rows (children) as part of the page.
49    ///
50    /// This mirrors TanStack's `paginateExpandedRows` behavior.
51    pub paginate_expanded_rows: bool,
52    /// If true, pinned rows can remain visible even if they are outside the current
53    /// filtered/sorted/paginated row set (TanStack `keepPinnedRows`).
54    pub keep_pinned_rows: bool,
55    /// Whether to allow column hiding at the table level (TanStack `enableHiding`).
56    pub enable_hiding: bool,
57    /// Whether to allow column ordering at the table level (TanStack `enableColumnOrdering`).
58    pub enable_column_ordering: bool,
59    /// Whether to allow column pinning at the table level (TanStack `enableColumnPinning` with
60    /// `enablePinning` fallback).
61    pub enable_column_pinning: bool,
62    /// Whether to allow row pinning at the table level (TanStack `enableRowPinning`).
63    pub enable_row_pinning: bool,
64    /// Whether to allow column resizing at the table level (TanStack `enableColumnResizing`).
65    pub enable_column_resizing: bool,
66    /// Enables/disables grouping for the table (TanStack `enableGrouping`).
67    pub enable_grouping: bool,
68    /// Enables/disables sorting for the table (TanStack `enableSorting`).
69    pub enable_sorting: bool,
70    /// Enables/disables multi-sort for the table (TanStack `enableMultiSort`).
71    pub enable_multi_sort: bool,
72    /// Maximum number of columns that can be multi-sorted (TanStack `maxMultiSortColCount`).
73    pub max_multi_sort_col_count: Option<usize>,
74    /// Enables/disables the ability to remove sorting (TanStack `enableSortingRemoval`).
75    pub enable_sorting_removal: bool,
76    /// Enables/disables the ability to remove multi-sorts (TanStack `enableMultiRemove`).
77    pub enable_multi_remove: bool,
78    /// When set, all sort toggles default to descending as their first toggle state
79    /// (TanStack `sortDescFirst`).
80    pub sort_desc_first: Option<bool>,
81    /// Enables/disables row selection for the table (TanStack `enableRowSelection`).
82    pub enable_row_selection: bool,
83    /// Enables/disables multi-row selection for the table (TanStack `enableMultiRowSelection`).
84    pub enable_multi_row_selection: bool,
85    /// Enables/disables sub-row selection propagation for the table (TanStack `enableSubRowSelection`).
86    pub enable_sub_row_selection: bool,
87    /// If enabled, grouping is assumed to be done externally (e.g. server-side).
88    ///
89    /// When `true`, `grouped_row_model()` returns `pre_grouped_row_model()`.
90    pub manual_grouping: bool,
91    /// Determines how grouped columns are ordered in the leaf column list (TanStack
92    /// `groupedColumnMode`).
93    pub grouped_column_mode: GroupedColumnMode,
94    /// Determines when `column_sizing` updates during a resize interaction (TanStack
95    /// `columnResizeMode`).
96    pub column_resize_mode: ColumnResizeMode,
97    /// Column resize direction for RTL layouts (TanStack `columnResizeDirection`).
98    pub column_resize_direction: ColumnResizeDirection,
99}
100
101impl Default for TableOptions {
102    fn default() -> Self {
103        Self {
104            enable_pinning: true,
105            manual_filtering: false,
106            enable_filters: true,
107            enable_column_filters: true,
108            enable_global_filter: true,
109            filter_from_leaf_rows: false,
110            max_leaf_row_filter_depth: 100,
111            manual_sorting: false,
112            manual_pagination: false,
113            auto_reset_page_index: None,
114            page_count: None,
115            row_count: None,
116            manual_expanding: false,
117            enable_expanding: true,
118            auto_reset_all: None,
119            auto_reset_expanded: None,
120            paginate_expanded_rows: true,
121            keep_pinned_rows: true,
122            enable_hiding: true,
123            enable_column_ordering: true,
124            enable_column_pinning: true,
125            enable_row_pinning: true,
126            enable_column_resizing: true,
127            enable_grouping: true,
128            enable_sorting: true,
129            enable_multi_sort: true,
130            max_multi_sort_col_count: None,
131            enable_sorting_removal: true,
132            enable_multi_remove: true,
133            sort_desc_first: None,
134            enable_row_selection: true,
135            enable_multi_row_selection: true,
136            enable_sub_row_selection: true,
137            manual_grouping: false,
138            grouped_column_mode: GroupedColumnMode::Reorder,
139            column_resize_mode: ColumnResizeMode::OnEnd,
140            column_resize_direction: ColumnResizeDirection::Ltr,
141        }
142    }
143}