# Field list

> How users build reports with the field list and its Filters, Columns, Rows and Values zones, by drag and drop or from the keyboard, and how to change fields from code.

The field list is where users build their report. It shows every field from the data and four zones that define the pivot:

| Zone | Effect |
| --- | --- |
| **Filters** | Fields that restrict the data without appearing in the table, such as channel or year |
| **Columns** | Fields whose members become column headers, such as quarter |
| **Rows** | Fields whose members become row headers, such as region and store |
| **Values** | Fields that are summarized in the cells, such as revenue, units and margin |

**Live demo: Retail sales report** (runs on the HTML version of this page). Source of `demos/pivot-studio-retail.ts`. Imports from `./_shared` and `./_scheduler-data` are sample data and small UI helpers used only by the docs.

```ts
import { createPivotStudio, type PivotReport } from '@birchui/pivot-studio';
import { docsTheme, layout, onDocsThemeChange, seededRandom } from './_shared';

export const meta = { title: 'Retail sales report', height: 600 };

interface SaleRecord {
  region: string;
  store: string;
  category: string;
  month: string;
  quarter: string;
  revenue: number;
  units: number;
  margin: number;
}

const STORES: [string, string][] = [
  ['North', 'Leeds Trinity'],
  ['North', 'Manchester Arndale'],
  ['North', 'Newcastle Eldon Square'],
  ['South', 'Brighton Churchill Square'],
  ['South', 'Southampton West Quay'],
  ['London', 'Covent Garden'],
  ['London', 'Westfield Stratford'],
  ['Scotland', 'Edinburgh St James'],
  ['Scotland', 'Glasgow Buchanan'],
];

const CATEGORIES: [string, number, number][] = [
  ['Outerwear', 89, 0.46],
  ['Footwear', 74, 0.41],
  ['Knitwear', 52, 0.52],
  ['Accessories', 24, 0.61],
  ['Denim', 58, 0.48],
];

function makeSales(): SaleRecord[] {
  const random = seededRandom(31);
  const records: SaleRecord[] = [];
  for (let m = 0; m < 12; m++) {
    const month = `2026-${String(m + 1).padStart(2, '0')}`;
    const quarter = `Q${Math.floor(m / 3) + 1}`;
    const season = m >= 9 || m <= 1 ? 1.35 : m >= 5 && m <= 7 ? 0.85 : 1;
    for (const [region, store] of STORES) {
      for (const [category, price, marginRate] of CATEGORIES) {
        const units = Math.round((40 + random() * 160) * season * (category === 'Outerwear' ? season : 1));
        const revenue = Math.round(units * price * (0.9 + random() * 0.2));
        records.push({
          region,
          store,
          category,
          month,
          quarter,
          revenue,
          units,
          margin: Math.round(revenue * marginRate),
        });
      }
    }
  }
  return records;
}

const report: PivotReport = {
  slice: {
    rows: [{ field: 'region' }, { field: 'store' }],
    columns: [{ field: 'quarter' }],
    values: [
      { field: 'revenue', aggregation: 'sum', caption: 'Revenue' },
      { field: 'margin', aggregation: 'sum', showAs: 'percentOfColumnTotal', caption: 'Margin share' },
    ],
  },
  formats: { revenue: { style: 'currency', currency: 'GBP', decimals: 0 } },
};

export default function mount(el: HTMLElement): () => void {
  const { toolbar, body, status } = layout(el);
  toolbar.append('Drag fields between Rows, Columns and Values, or click a cell to drill through to its records.');
  const studio = createPivotStudio<SaleRecord>(body, {
    data: makeSales(),
    report,
    theme: docsTheme(),
    height: '100%',
    fileName: 'retail-sales-2026',
    ariaLabel: 'Retail sales pivot report',
  });
  const offs = [
    studio.on('pivotUpdated', () => {
      const slice = studio.getReport().slice;
      const names = (list: { field: string }[] | undefined) => (list ?? []).map((f) => f.field).join(', ') || 'none';
      status.textContent = `Rows: ${names(slice.rows)}. Columns: ${names(slice.columns)}. Values: ${names(slice.values)}.`;
    }),
    studio.on('error', ({ message }) => {
      status.textContent = message;
    }),
  ];
  status.textContent = 'Loading 540 sales records…';
  const stopTheme = onDocsThemeChange((theme) => studio.update({ theme }));
  return () => {
    for (const off of offs) off();
    stopTheme();
    studio.destroy();
  };
}
```

## The field list

The list at the top of the panel shows every visible field with its caption; date fields are followed by their derived levels ("Order date › Year", "Order date › Quarter" and so on). Fields already used in the report are marked. Type in **Search fields** to narrow the list, which helps with wide datasets.

The toolbar's **Fields** button shows and hides the panel. Set `fieldList: false` to start with it hidden, for example when you embed a fixed report that users should read rather than change; the toolbar button still lets them open it unless you also hide the toolbar with `toolbar: false`.

## Drag and drop

- Drag a field from the list onto a zone to add it. A marker shows where it will land among the zone's chips.
- Drag a chip within a zone to reorder it, for example to put store above region.
- Drag a chip to another zone to move it.
- Drag a chip back onto the field list to remove it from the report.

A field can be in only one of Rows, Columns and Filters at a time: adding it to another of these zones moves it, keeping its sort settings. A field can appear in Values several times, for example revenue as a sum and as a percentage of the column total.

## Chips

Each field in a zone is shown as a chip:

- **Row, column and filter chips** have a filter button; a filtered chip is marked and announced as filtered. See [Filtering & sorting](https://docs.birchui.com/pivot-studio/filtering-and-sorting.md).
- **Value chips** show their aggregation, such as "Sum" or "Median", as a button that opens the value menu.
- Every chip has a remove button.

Opening a chip shows its menu:

| Chip | Menu |
| --- | --- |
| Rows and columns | Sort A to Z or Z to A, sort by each measure (largest or smallest first), Filter…, Clear filter (when filtered), Expand all and Collapse all (when the zone has more than one field), Move to another zone, Move up, Move down, Remove |
| Filters | Sort A to Z or Z to A, Filter…, Clear filter, Move to another zone, Move up, Move down, Remove |
| Values | Summarize by, Show values as, Decimal places, Move to another zone, Move up, Move down, Remove |

## Keyboard

The field list and each zone are listboxes with one tab stop each.

| Key | In the field list | On a chip in a zone |
| --- | --- | --- |
| <kbd>Arrow Up</kbd> / <kbd>Arrow Down</kbd> | Move between fields | Move between chips |
| <kbd>Home</kbd> / <kbd>End</kbd> | First or last field | First or last chip |
| <kbd>Enter</kbd> or <kbd>Space</kbd> | Open the field menu: **Add to filters**, **Add to columns**, **Add to rows**, **Add to values**, or **Remove from report** | Open the chip menu |
| <kbd>Alt</kbd> + <kbd>Arrow Up</kbd> / <kbd>Arrow Down</kbd> | | Move the chip one position up or down |
| <kbd>Delete</kbd> or <kbd>Backspace</kbd> | | Remove the chip |

From the search box, <kbd>Arrow Down</kbd> moves to the first matching field. Every change is announced through a polite live region, for example "Region moved to position 1 of 2 in Rows", and focus stays on the moved chip.

So a keyboard user builds "revenue by region and quarter" like this: focus the field list, move to Region, press <kbd>Enter</kbd> and choose Add to rows; move to Order date › Quarter and choose Add to columns; move to Revenue and choose Add to values.

## Changing fields from code

```ts title="report-buttons.ts"
studio.addField('rows', 'region');
studio.addField('rows', 'store');
studio.addField('columns', 'orderDate.quarter');
studio.addField('values', 'revenue');
studio.addField('values', 'margin');

studio.moveField('store', 'rows', 0);
studio.moveField('orderDate.quarter', 'filters');
studio.removeField('margin');
studio.removeField('region', 'rows');
studio.swapAxes();
```

| Method | Effect |
| --- | --- |
| `addField(zone, field, index?)` | Add a field to `'rows'`, `'columns'`, `'filters'` or `'values'`, at an optional position. Adding a field that does not exist logs a warning and does nothing. |
| `moveField(field, zone, index?)` | Move a field to another position or to `'rows'`, `'columns'` or `'filters'` |
| `removeField(field, zone?)` | Remove a field from one zone, or from every zone. Removing a field from its last dimension zone also clears its filter. |
| `swapAxes()` | Exchange the row and column fields, like the toolbar's **Swap axes** button |

Number fields added to Values are summed; other fields are counted. Change that with `setAggregation()`; see [Calculations](https://docs.birchui.com/pivot-studio/calculations.md).

All of these update the table and fire `reportChange`, the same as user edits.

## Fixed reports

To show a report that users cannot rearrange, hide both the field list and the toolbar:

```ts
createPivotStudio(container, {
  data: sales,
  report: quarterlyStoreReport,
  fieldList: false,
  toolbar: false,
});
```

Users can still expand and collapse members, sort from the headers and drill through to records. Set `drillThrough: false` as well to remove the drill-through dialog.
