Skip to content

Compare Table

A table of properties by columns of values, such as source, local, and after sync. A row whose values differ wears the accent wash, and each value that differs from the first column is bold. A Show only changes toggle hides the rows that match. Section rows group the rows under a heading, and note rows add a line of detail. It is a Data Table with no sort, search, or selection.

Decision

When Use
Showing what a sync or an import would change before it runs Compare Table
The values of one thing Definition List
Rows the reader sorts, searches, or selects Data Table

Usage

import { createCompareTable } from './configurationpage?name=myplugin_stolon.js';

var diff = createCompareTable({
    rows: [
        { key: 'title', label: 'Title', values: { source: 'Alien', local: 'Alien', after: 'Alien' } },
        { key: 'year', label: 'Year', values: { source: 1979, local: 1980, after: 1979 } }
    ],
    onlyChanges: true
});
view.querySelector('#diffHost').appendChild(diff.element);

Group the rows under section headings, and explain a change with a note:

diff.setRows([
    { section: 'Metadata' },
    { key: 'year', label: 'Year', values: { source: 1979, local: 1980, after: 1979 } },
    { note: 'Changed because the source has a new release date.' },
    { section: 'Genres' },
    { key: 'genres', label: 'Genres', values: { source: 'Horror, Sci-Fi', local: 'Horror', after: 'Horror, Sci-Fi' } }
]);

Classes: stolon-compare-table, stolon-compare-toggle, stolon-compare-value with stolon-differs and stolon-missing, stolon-compare-section, stolon-compare-note. The handle is { element, setRows, getOnlyChanges, setOnlyChanges, getChanged, destroy }.

States and Modifiers

  • A row is { key, label, values }, where values holds a value per column key. A missing value shows "None" by missingText, dimmed.
  • columns is an array of { key, label, icon }, Source, Local, and After sync by default, keyed source, local, and after. propertyHeader heads the first column, "Property" by default.
  • A changed row has changed. getChanged() gives the keys of the changed rows.
  • { section } draws a small uppercase dimmed heading across every column, with stolon-compare-section, over the rows after it up to the next section. A section with no row shown under it hides.
  • { note } draws a dimmed line across every column, with stolon-compare-note, that wraps rather than cut off. It shows only while the row before it shows, so with only changes shown a note hides with its unchanged row.
  • A section or note may carry a key, else it takes one from its place. Neither is ever changed, sorted, or counted by getChanged().
  • The toggle sits in the table's toolbar, "Show only changes" by changesText. onlyChanges: true starts with it on, and onChange(onlyChanges) hears it. With it on and nothing changed, the table says "No changes." by noChangesText. With no rows it says "Nothing to compare." by emptyText.
  • label names the table, "Comparison" by default. height and maxHeight work as the Data Table's do.

Reference

Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.

createCompareTable

function createCompareTable(options?: CompareTableOptions): CompareTableHandle

A table of properties by columns of values, such as source, local, and after sync. A row whose values differ is changed: it wears the accent wash, and each value that differs from the first column is marked. A Show only changes toggle hides the rows that match. It is a Data Table with no sort, search, or selection. A section row heads the rows after it and a note row adds a line of detail, each across every column. With only changes shown, a section hides while no row under it shows, and a note shows only while the row before it shows.

Option Type What it does
rows CompareTableEntry[] | null array of { key, label, values: { columnKey: value } }, { section } for a heading over the rows after it, or { note } for a dimmed line across every column [optional]
columns CompareTableColumn[] | null array of { key, label, icon } (default Source, Local, and After sync, keyed source, local, and after)
propertyHeader string header of the property column (default 'Property')
onlyChanges boolean true starts with only the changed rows shown (default false)
changesText string label of the toggle (default 'Show only changes')
emptyText string shown while there is no row (default 'Nothing to compare.')
noChangesText string shown while only changes are shown and none changed (default 'No changes.')
missingText string shown for a missing value (default 'None')
label string aria-label of the table (default 'Comparison')
height ListHeight
maxHeight number | string | null
size 'small' | 'medium' | 'large' 'small', 'medium', or 'large' for its fields (default 'medium')
onChange (onlyChanges: boolean): void function(onlyChanges) after the toggle changes [optional]
Handle member Type
setRows (rows: CompareTableEntry[] | null): void
getOnlyChanges (): boolean
setOnlyChanges (on: boolean): void
getChanged (): string[]
destroy (): void
Type What it is
CompareTableRow One compared property: its key, its label, and its value in each column by column key.
CompareTableSection A heading row across every column that groups the rows after it, up to the next heading. key names it, else one is made.
CompareTableNote A dimmed text row across every column, such as why a group changed. It shows while the row before it shows.
CompareTableEntry One entry of a compare table: a compared row, a section heading, or a note.
CompareTableColumn One column of values, such as the source, the local copy, or the result after a sync.
Class What it looks like
stolon-compare-toggle A Data Table of properties by columns of values, with a Show Only Changes toggle in its toolbar
stolon-compare-table A row whose values differ, in the accent wash
stolon-compare-value One value. A value that differs from the first column is bold, and a missing one is dimmed
stolon-compare-section A section row, one small uppercase dimmed heading across every column over the rows it groups
stolon-compare-note A note row, a dimmed line of detail across every column that wraps rather than cut off

Example

Example Code

<!-- title: Compare Table -->
<div id="compare" style="display: flex; flex-direction: column; gap: 24px;"></div>
<script type="module">
const base = await window.__baseReady;
const mount = document.getElementById('compare');
const table = base.createCompareTable({
    rows: [
        { key: 'title', label: 'Title', values: { source: 'Alien', local: 'Alien', after: 'Alien' } },
        { key: 'year', label: 'Year', values: { source: 1979, local: 1980, after: 1979 } },
        { key: 'rating', label: 'Rating', values: { source: 'R', local: '', after: 'R' } },
        { key: 'played', label: 'Played', values: { source: 'Yes', local: 'No', after: 'Yes' } },
        { key: 'path', label: 'Path', values: { source: '/media/movies/Alien (1979)', local: '/media/movies/Alien (1979)', after: '/media/movies/Alien (1979)' } }
    ]
});
mount.appendChild(table.element);
const grouped = base.createCompareTable({
    rows: [
        { section: 'Metadata' },
        { key: 'name', label: 'Name', values: { source: 'Alien', local: 'Alien', after: 'Alien' } },
        { key: 'overview', label: 'Overview', values: { source: 'The crew of the Nostromo answers a distress call.', local: 'A crew answers a distress call.', after: 'The crew of the Nostromo answers a distress call.' } },
        { note: 'Changed because the source has a new overview.' },
        { section: 'Genres' },
        { key: 'genres', label: 'Genres', values: { source: 'Horror, Sci-Fi', local: 'Horror', after: 'Horror, Sci-Fi' } },
        { section: 'Tags' },
        { key: 'tags', label: 'Tags', values: { source: 'Classic', local: 'Classic', after: 'Classic' } },
        { section: 'Studios' },
        { key: 'studios', label: 'Studios', values: { source: 'Brandywine', local: 'Brandywine', after: 'Brandywine' } }
    ],
    onlyChanges: true
});
mount.appendChild(grouped.element);
</script>