Skip to main content

sqlly_datatable/
lib.rs

1//! Configurable virtualized data grid for the [GPUI] toolkit.
2//!
3//! `sqlly-datatable` provides a self-contained `Entity<GridState>` widget that
4//! you can drop into a GPUI application. It supports:
5//!
6//! * Virtualized rendering for large datasets.
7//! * Cell, row, column and rectangular drag selection.
8//! * Sorting on column headers, with a cycle through ascending, descending,
9//!   and unsorted.
10//! * Per-column filtering via a rich filter panel (operator predicates,
11//!   value checklist, search) opened from the built-in context menu.
12//! * Expandable row sections created by grouping on any column from its
13//!   built-in context menu or through [`GridState::set_grouped_column`].
14//! * Configurable column resizing, mouse-driven scrollbars, and edge-scroll
15//!   during drag selection.
16//! * Clipboard copy of any selection (with or without headers).
17//! * An optional **pivot tab** ([`SqllyDataTableBuilder::pivot`]): a
18//!   cross-tabulation view with a drag-and-drop field sidebar (rows /
19//!   columns / values / filters), count/sum/avg/min/max aggregation,
20//!   expandable row and column groups, subtotals and grand totals, sorting
21//!   on labels or values, source-value filters, and CSV export. The pivot
22//!   reads a shared snapshot of the grid's rows and never mutates them;
23//!   switching tabs preserves both views' state. Configure it
24//!   programmatically via [`pivot::PivotConfig`] and read the live layout
25//!   back from [`pivot::PivotState::config`]. Pivot row height and column
26//!   width can be initialized on the builder, resized in the view, and read
27//!   or updated through [`pivot::PivotState`]. Right-clicks surface to a
28//!   [`pivot::PivotContextMenuProvider`] with full context (grouping paths,
29//!   aggregated value, driving source rows), and double-clicking any value
30//!   cell drills through: the flat grid is filtered to exactly the rows
31//!   behind that cell and brought to the front.
32//!
33//! The crate is intentionally GPUI-only on the UI side; the pure formatter in
34//! [`mod@format`] is usable in any context (export pipelines, server-side preview,
35//! etc.). All formatting is configurable per column by composing the
36//! [`config::GridConfig`] defaults with [`config::ColumnOverride`] entries.
37//!
38//! # Quick start
39//!
40//! ```no_run
41//! use gpui::App;
42//! use sqlly_datatable::{
43//!     CellValue, Column, ColumnKind, GridConfig, GridData, SqllyDataTable,
44//! };
45//!
46//! let data = GridData::new(
47//!     vec![Column { name: "id".into(), kind: ColumnKind::Integer, width: 80.0 }],
48//!     vec![vec![CellValue::Integer(1)], vec![CellValue::Integer(2)]],
49//! ).expect("rectangular data");
50//! let app = gpui::Application::new();
51//! app.run(|cx: &mut App| {
52//!     let _view = SqllyDataTable::builder(data)
53//!         .config(GridConfig::default())
54//!         .build(cx);
55//! });
56//! ```
57//!
58//! See `crates/sqlly-datatable-sample` for a runnable demo.
59//!
60//! [GPUI]: https://github.com/zed-industries/gpui
61
62// `missing_docs` is intentionally not enabled at the crate level. The public
63// surfaces documented here are stable; private internals will get docs as the
64// `grid::` modules mature. Run clippy with
65// `#![warn(missing_docs)]` in scope when cleaning up a module.
66
67pub mod config;
68pub mod data;
69pub mod filter;
70pub mod format;
71pub mod grid;
72pub mod pivot;
73
74pub use config::{
75    BooleanFormat, ColumnOverride, DateFormat, GridConfig, KeyBinding, KeyBindings, NullFormat,
76    NumberFormat, RelativeDateFormat, RelativeUnit, ReplacementRule, ReplacementTiming,
77    ResolvedColumnFormat, StringFormat, TextAlignment, TextCase, TruncationBehavior,
78};
79pub use data::{
80    compare_cells, sample_data, CellValue, Column, ColumnKind, GridData, GridDataError,
81};
82pub use filter::{ColumnFilter, FilterPredicate, NumberOp, TextOp};
83pub use grid::{
84    BusyState, ColumnContext, ContextMenu, ContextMenuItem, ContextMenuProvider,
85    ContextMenuRequest, ContextMenuSelection, ContextMenuTarget, FilterPanel, GridState, GridTab,
86    GridTheme, HitResult, MenuAction, MenuItem, PivotSidebarPosition, RowGroup, RowWindow,
87    ScrollbarAxis, SelectedCellContext, SelectedRowContext, Selection, SortDirection,
88    SqllyDataTable, SqllyDataTableBuilder,
89};
90pub use pivot::{
91    AggregationFn, PivotCellContext, PivotConfig, PivotContextMenuProvider,
92    PivotContextMenuRequest, PivotFormatDialog, PivotGrid, PivotMenuItem, PivotMenuTarget,
93    PivotPathComponent, PivotResult, PivotSaveConfigHandler, PivotSidebar, PivotSortKey,
94    PivotState, PivotZone, DEFAULT_PIVOT_COLUMN_WIDTH, DEFAULT_PIVOT_ROW_HEIGHT,
95    DEFAULT_PIVOT_SIDEBAR_WIDTH, MIN_PIVOT_COLUMN_WIDTH, MIN_PIVOT_ROW_HEIGHT,
96};