AutoFilter
AutoFilter adds native Excel filter and sort dropdowns to the column headers. Clicking a dropdown lets users filter visible rows, sort by value, or apply custom criteria — all within Excel without any additional configuration.
Default behavior by mode
The default differs between the two schema modes:
| Mode | AutoFilter default | How to change |
|---|---|---|
| Report | Off | Set autoFilter: true on the table input |
| Excel table | On | Set autoFilter: false on the table input |
This asymmetry reflects how Excel itself works: native excel tables always have filter dropdowns by default, while plain worksheet ranges do not.
Report mode: opting in
import { createExcelSchema, createWorkbook } from "@chronicstone/typed-xlsx";
const schema = createExcelSchema<{ region: string; amount: number }>()
.column("region", { accessor: "region" })
.column("amount", { accessor: "amount", style: { numFmt: "$#,##0.00" } })
.build();
const workbook = createWorkbook();
workbook.sheet("Sales").table("sales", {
schema,
rows: [
{ region: "EMEA", amount: 45000 },
{ region: "AMER", amount: 62000 },
],
autoFilter: true, // Adds filter dropdowns to report table headers
});
const buffer = workbook.toBuffer();
You can also pass { enabled: true } for the object form:
import { createExcelSchema, createWorkbook } from "@chronicstone/typed-xlsx";
const schema = createExcelSchema<{ region: string; amount: number }>()
.column("region", { accessor: "region" })
.column("amount", { accessor: "amount" })
.build();
const workbook = createWorkbook();
workbook.sheet("Sales").table("sales", {
schema,
rows: [],
autoFilter: { enabled: true },
});
Excel table mode: opting out
import { createExcelSchema, createWorkbook } from "@chronicstone/typed-xlsx";
const schema = createExcelSchema<{ product: string; stock: number }>({ mode: "excel-table" })
.column("product", { accessor: "product" })
.column("stock", { accessor: "stock" })
.build();
const workbook = createWorkbook();
workbook.sheet("Inventory").table("inventory", {
schema,
rows: [{ product: "Widget A", stock: 120 }],
autoFilter: false, // Disable the default autoFilter on this excel table
});
const buffer = workbook.toBuffer();
Incompatibility with sub-row expansion
AutoFilter is silently disabled (with a console.warn) when a report table uses sub-row expansion (an accessor that returns an array). Sub-row expansion creates merged cells, and Excel cannot apply autoFilter over a range that contains merged cells.
This only applies to report mode — excel-table mode doesn't support sub-row expansion at all (it throws at output time), so this conflict cannot arise.
If you see the warning and want to suppress it, either remove autoFilter: true from that table or remove the array-returning accessor causing the expansion.