Class DataCollectionState<TItem>
- Namespace
- BlazOrbit.Components
- Assembly
- BlazOrbit.dll
Maintains the state for data collection components including pagination, filtering, sorting, and selection.
public sealed class DataCollectionState<TItem>
Type Parameters
TItemThe type of the items in the collection.
- Inheritance
-
objectDataCollectionState<TItem>
Constructors
DataCollectionState()
public DataCollectionState()
Properties
ColumnFilters
Active per-column filter entries keyed by column header. Combined with FilterText using AND semantics — a row must match the global filter AND every column-scoped filter to remain visible. Mutate via SetColumnFilter(string, string) / SetColumnFilter(string, ColumnFilterEntry) / ClearColumnFilter(string) / ClearAllColumnFilters().
public IReadOnlyDictionary<string, ColumnFilterEntry> ColumnFilters { get; }
Property Value
- IReadOnlyDictionary<string, ColumnFilterEntry>
ColumnOrder
Active column ordering by header name. Empty means "use the registration order". Mutate via MoveColumn(string, int, IEnumerable<string>) / SetColumnOrder(IEnumerable<string>) / ClearColumnOrder().
public IReadOnlyList<string> ColumnOrder { get; }
Property Value
- IReadOnlyList<string>
ColumnWidths
Live column widths in pixels, keyed by header name. Empty by default — populated
when the user drags the resize handle in BOBDataGrid. Mutate via
SetColumnWidth(string, double) / ClearColumnWidth(string) /
ClearAllColumnWidths().
public IReadOnlyDictionary<string, double> ColumnWidths { get; }
Property Value
- IReadOnlyDictionary<string, double>
CurrentPage
The current page number.
public int CurrentPage { get; set; }
Property Value
- int
FilterText
The current filter text.
public string FilterText { get; set; }
Property Value
- string
PageSize
The number of items displayed per page.
public int PageSize { get; set; }
Property Value
- int
SelectedItems
The set of currently selected items.
public IReadOnlySet<TItem> SelectedItems { get; }
Property Value
- IReadOnlySet<TItem>
SortColumn
The name of the primary sort column (first descriptor in SortDescriptors). Kept as a writeable shortcut for backward compatibility with existing single-sort code.
public string? SortColumn { get; set; }
Property Value
- string
SortDescriptors
Active sort descriptors in priority order (primary first). When empty, no sort is applied. Use ToggleSort(string, bool) from the component layer to manipulate this list — direct mutation is allowed for advanced scenarios but the renderer expects the indices to stay 1-based contiguous.
public IReadOnlyList<SortDescriptor> SortDescriptors { get; }
Property Value
- IReadOnlyList<SortDescriptor>
SortDirection
The current direction of the primary sort. Maps to the first descriptor in SortDescriptors; setting it updates that descriptor in place.
public SortDirection SortDirection { get; set; }
Property Value
Methods
ClearAllColumnFilters()
Drops every per-column filter while preserving FilterText.
public void ClearAllColumnFilters()
ClearAllColumnWidths()
Drops every runtime width override.
public void ClearAllColumnWidths()
ClearColumnFilter(string)
Removes the per-column filter for the given column header.
public void ClearColumnFilter(string columnName)
Parameters
columnNamestring
ClearColumnOrder()
Drops the custom column order and reverts to the registry's natural order.
public void ClearColumnOrder()
ClearColumnWidth(string)
Drops the runtime width override for a single column.
public void ClearColumnWidth(string columnName)
Parameters
columnNamestring
ClearSelection()
Clears all selected items.
public void ClearSelection()
ClearSort()
Drops every active sort descriptor.
public void ClearSort()
IsSelected(TItem)
Determines whether the specified item is selected.
public bool IsSelected(TItem item)
Parameters
itemTItemThe item to check.
Returns
LoadFromJson(string?)
Restores state from a JSON payload produced by ToJson(). Malformed input is silently dropped so a corrupted localStorage entry does not block the grid from rendering.
public void LoadFromJson(string? json)
Parameters
jsonstring
MoveColumn(string, int, IEnumerable<string>)
Shifts a column by delta positions in the visible order. The
state lazily seeds itself from referenceOrder on the first move
so consumers don't have to call SetColumnOrder(IEnumerable<string>) first.
public void MoveColumn(string columnName, int delta, IEnumerable<string> referenceOrder)
Parameters
columnNamestringHeader of the column being moved (case-insensitive).
deltaintPositive moves toward the end, negative toward the start. Out-of-bounds is silently clamped.
referenceOrderIEnumerable<string>Source-of-truth ordering used when ColumnOrder is empty.
ResetPagination()
Resets the current page to the first page.
public void ResetPagination()
SelectAll(IEnumerable<TItem>)
Selects all items in the specified collection.
public void SelectAll(IEnumerable<TItem> items)
Parameters
itemsIEnumerable<TItem>The items to select.
SelectItem(TItem, SelectionMode)
Toggles the selection state of the specified item.
public void SelectItem(TItem item, SelectionMode mode)
Parameters
itemTItemThe item to toggle.
modeSelectionModeThe selection mode.
SetColumnFilter(string, ColumnFilterEntry)
Sets the full filter entry (text + operator + mode) for a column.
public void SetColumnFilter(string columnName, ColumnFilterEntry entry)
Parameters
columnNamestringentryColumnFilterEntry
SetColumnFilter(string, string)
Sets the filter text for a specific column with default Contains
- Text semantics. Whitespace / empty clears the entry. Column lookup is case-insensitive against the column header.
public void SetColumnFilter(string columnName, string filter)
Parameters
columnNamestringfilterstring
SetColumnFilterOperator(string, ColumnFilterOperator)
Updates only the operator for an existing column-filter entry. No-op when the column has no active filter — typing the text comes first.
public void SetColumnFilterOperator(string columnName, ColumnFilterOperator op)
Parameters
columnNamestringopColumnFilterOperator
SetColumnOrder(IEnumerable<string>)
Replaces the column order with the supplied sequence. Pass an empty enumerable to revert to the registration order.
public void SetColumnOrder(IEnumerable<string> headers)
Parameters
headersIEnumerable<string>
SetColumnWidth(string, double)
Sets a runtime width (in pixels) for the named column.
public void SetColumnWidth(string columnName, double widthPx)
Parameters
columnNamestringwidthPxdouble
ToJson()
Serialises the persistable slice of state (filter / sort / page / column order / column filters) to a JSON payload suitable for round-tripping through IDataCollectionStatePersistence. Selection is intentionally excluded — selected items reference live data that may not be present after a reload.
public string ToJson()
Returns
- string
ToggleSort(string)
Toggle the sort state for a column. Single-sort semantics: cycles
the column through Asc → Desc → None and replaces any existing
sort. Use ToggleSort(string, bool) with
append=true to add a tie-breaker without dropping prior
sort levels (multi-column sort).
public void ToggleSort(string columnName)
Parameters
columnNamestring
ToggleSort(string, bool)
Toggle the sort state for a column. When append
is true, the column joins (or cycles within)
the existing descriptor list as the next priority instead of
replacing it — wires Shift+Click for multi-column sort.
public void ToggleSort(string columnName, bool append)
Parameters
columnNamestringappendbool