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