positron-data-grid-pattern

Guides implementation of virtualized grid UIs in Positron using DataGridInstance subclasses.

4.2k|179|Updated May 24, 2022
One-click install
npx skills add https://github.com/posit-dev/positron --skill positron-data-grid-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: positron-data-grid-pattern
Source: https://github.com/posit-dev/positron/tree/main/.claude/skills/positron-data-grid-pattern
Command: npx skills add https://github.com/posit-dev/positron --skill positron-data-grid-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building list, table, or grid UIs in Positron often leads developers to wrap the grid in a React component that mediates props into a DataGridInstance via useEffect, which is an anti-pattern. This Skill teaches the correct architecture where the DataGridInstance subclass itself owns data, layout, selection, and events.

Core Features & Use Cases

  • Correct Architecture Guidance: Explains that a DataGridInstance subclass IS the data grid, with <PositronDataGrid /> acting only as a thin renderer.
  • Two Data Strategies: Covers the embed strategy (e.g. PositronListInstance with setItems) for small datasets and the fetchData strategy (e.g. TableDataDataGridInstance) for large virtualized datasets backed by comms or files.
  • Anti-Pattern Detection: Lists symptoms of the wrong approach, such as piles of useEffects pushing props into the instance or re-creating instances when options change.
  • Use Case: When adding a new column picker or data preview panel in Positron, subclass DataGridInstance, create one instance via useState, subscribe to its events, dispose on unmount, and render with <PositronDataGrid instance={instance} />.

Quick Start

Ask the assistant to scaffold a new virtualized grid UI in Positron following the DataGridInstance pattern for your dataset size.

Frequently Asked Questions about positron-data-grid-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a virtualized grid UI in Positron?

Subclass DataGridInstance (or PositronListInstance for simple lists), create one instance with useState(() => new MySubclass(...)), subscribe to its events, dispose on unmount, and render it with <PositronDataGrid instance={instance} />. The instance owns all data and state.

What is the difference between embed and fetchData data strategies?

The embed strategy holds the full dataset in memory and receives items via a setter like setItems, suiting small bounded lists. The fetchData strategy connects to a backend and populates a cache when the base class requests visible viewport cells, suiting huge datasets.

Why is wrapping PositronDataGrid in a React component an anti-pattern?

A wrapper that pushes props into the instance via useEffect duplicates state ownership and creates fragile synchronization code. The DataGridInstance subclass is already the API surface, so callers should drive it directly instead of mediating through React props.

Which existing DataGridInstance subclasses should I read before writing a new one?

Read PositronListInstance for the embed strategy and TableDataDataGridInstance or TableSummaryDataGridInstance for the fetchData strategy. InlineTableDataGridInstance and ColumnSelectorDataGridInstance are additional fetchData examples.

When should I add a new option to the DataGridInstance base class?

Only when a needed behavior cannot be expressed through existing subclass options, since changing the base class affects all subclasses. The path is adding the option to the base options type, plumbing it to the relevant subsystem, and updating existing subclasses.