file-system-js: File System (1k to 1M items as a tree)
The tree-rows demo: no backend, no network calls. A single <vn-grid> in
tree mode, fed a client-generated file system (folders and files)
through StaticDataManager: 1,000 items by default, selectable up to
1,000,000 from the toolbar. It shows the grid's tree rows
(docs/vanilla-grid/24-tree-rows-implementation.md)
on a dataset of its own, separate from large-dataset-js, whose rows are a flat
list of people. A preview pane beside the grid shows the selected row.
What it shows
- A tree built from a parent key. Every row has an
idand aparentId(nullfor the six top-level folders).app.jspassestree: { parentField: 'parentId', column: 'name', expandMode: 'collapsed' }toinitializeGrid(), so the grid opens with only the top-level folders shown, collapsed, as a file explorer does. The Name column is the tree column: each row is indented by its depth, and every non-empty folder carries an expand/collapse toggle. - Rows out of tree order. The generator emits the tree level by level: a folder's children are emitted together, after every folder queued before it, so a child arrives long after its parent. The grid's depth-first build is what puts each row under its parent.
- A deep, uneven tree. A folder gets 0 to 5 subfolders and 1 to 10 files, 12 levels at most, and a few folders are left empty: leaves with no toggle. At 1,000,000 items the tree runs the full 12 levels deep.
- Expand and collapse. Click a toggle, or focus it and press Enter or
Space; Shift-click or Shift+Enter applies the new state to the whole subtree.
The toolbar's Expand all and Collapse all are the toolbar's standard
expandAllRows/collapseAllRowscommands, shown by theisTreeModestate predicate (show-when="isTreeMode"), so they appear only while the grid shows a tree. A toggle splices the projection, so it stays in the milliseconds at 1,000,000 items. - Search and filters keep the folders. The toolbar search
(
<vn-grid-toolbar-search>, over Name, Kind and Owner) and the column filters show each match under its folders: the manager adds every match's ancestors as dimmed context rows, and everything is expanded while a search or filter is active. Clearing them brings back the expand state you had. A file name embeds its id (report-4217.pdf), so searching one file finds exactly it. The grid carrieshighlight-search-matches, so the term is marked where it occurs: Kind and Owner are plain cells, and the Name renderer writes the name with<vn-grid>.setSearchHighlightedText(). - Sorting within siblings. A header sort (Size, say) orders each folder's children; children always stay under their parent.
- Columns. Name (a folder or file glyph from
renderCell, which in tree mode renders into the tree cell's content span, after the indent and the toggle), Kind, Size (raw bytes for sorting and filtering, shown as "1.2 MB"; a folder's size is the sum of its subtree), Items (a folder's direct children), Modified (datetime), Owner and Read-only (boolean). - Export. The toolbar's export writes the tree flat, in tree order, collapsed rows included.
- A preview pane. The grid uses
selection-mode="single"with the checkbox column turned off (selection: { showCheckboxes: false }), so a click selects a row, shown by the theme's selected tint and marker; clicking it again clears the selection. The pane on the right followsvn-grid-selection-changed: the type's icon (a folder, or a colored page with the extension), a fake preview of the contents, the same for every file of a type (a document page, a spreadsheet, CSV or text lines, code, a picture, an audio or video player whose duration follows the file's size, an archive listing; a folder states its item count), and the row's details, formatted as the cells show them (grid.formatValue()). With nothing selected it shows a prompt. A tree size switch clears the selection. - Two panes and a splitter. The toolbar and grid on the left, two thirds
of the width at first, the preview on the right. The splitter between them
is northwind-customers-js's: drag it, or focus it and use the arrow keys
(Shift for larger steps), double-click it to split evenly; it stops at each
pane's minimum width, and the split is kept in
localStorage(file-system-js:splitterSizes). The preview's minimum is 280px. The list's is 1,200px, room for every column at its default width, and never less than the toolbar on one row, so its commands never wrap to a second row (that row stays under 1,200px in every theme; a longer status text, a translation say, would raise the minimum). Below 1530px the preview stacks under the list, the splitter turns horizontal, and the toolbar wraps again on a window narrower than its row. - 15 built-in themes from the toolbar's theme selector, and a page canvas
that follows the theme's light or dark mode, as in
large-dataset-js. The preview pane follows it too, and the splitter turns to the theme's accent color on hover, focus and drag. - Settings persistence.
storage-mode="local"keeps the column layout and the sort across visits. The expand state is not persisted. - App preferences. The selected theme and tree size are remembered by the
app itself (
prefs.js, under thefile-system-js:key prefix), and the split bysplitter.js, under the same prefix.
Script load order
prefs.js, theme-selector.js and rows-selector.js are plain scripts loaded
before vanilla-grid-toolbar.js: the toolbar renders its first template
synchronously when it is defined, so <file-system-theme-selector> and
<file-system-rows-selector> must already be defined by then, and the theme
selector restores a persisted theme while the document is still parsing,
before <vn-grid> upgrades. app.js is a module and runs last; it imports
splitter.js and preview.js.
Run
Serve the workspace root with any static server, then open
/samples/file-system-js/index.html. No backend or network access is needed.
Test hook:
?rows=<n>pins the tree size and wins over the toolbar dropdown, which then renders nothing (tests/playwright/file-system-js-smoke.spec.jsandtests/playwright/file-system-js-preview.spec.jspass?rows=1000). Without it the demo opens at the last size picked (1,000 on a first visit).
Files
index.html: the two panes (the toolbar and grid, the preview) and the splitter between them, the loading overlay, the script load order.app.js:type="module"bootstrap. Generates the tree (seeded, so a reload shows the same tree; in 50,000-row chunks behind the loading overlay's progress readout), defines the columns, wires oneStaticDataManagerfor the page's lifetime, initializes the grid in tree mode with single selection, wires the splitter and the preview to the selection, and handlesfile-system-js:rowcountchangeby clearing the selection, releasing the old tree and generating the new one.preview.js:showPreview(), which fills the preview pane: the type icons, the fake preview of each type and the details list.splitter.js: the splitter, a copy of northwind-customers-js'smodules/splitter.js(a change to one belongs in both).prefs.js: the sample'slocalStorage-backed preference store (window.FileSystemPrefs) for the theme and the tree size, the default size, the?rows=override and the size currently shown.theme-selector.js:<file-system-theme-selector>, the theme dropdown, plus the loading-overlay helpers.rows-selector.js:<file-system-rows-selector>, the tree-size dropdown (1,000 / 10,000 / 100,000 / 500,000 / 1,000,000). It only announces the change;app.jsowns the regeneration.styles.css: the two-pane layout and the splitter, the loading overlay, the selector skin, the theme-aware canvas and accent, the Name column's glyphs, and the preview pane.