Data
Sort the cells, or just the view
Sort 40 orders in place, as Excel does, or for the view only. Then check what the formulas on the Watch sheet read.
Engine @sheetwrite/formulas
- Orders
- 40
- Formulas
- 46
Try it
How the sort treats the workbook
- Values, formulas, styles and notes move with their row. A formula that reads its own row, like
=D1*E1, keeps reading it. - Formulas outside the range keep their references, so they read the new order.
- Text sorts case-insensitively in Excel's order, and blank cells are last in both directions.
- Collaborators receive an in-place sort as one transaction. A view sort is saved with the sheet and exports to Excel as its sort state.
The code behind it
import "@sheetwrite/core/styles.css";
// An "orders" sheet: a header row and 39 orders in columns A to F
// The grid fills its host, so the host needs a heightconst host = document.querySelector<HTMLElement>("#grid");if (host === null) throw new Error("Missing #grid host");host.style.height = "480px";
const orders = { sheet: "orders", start: { row: 0, col: 0 }, end: { row: 39, col: 5 } };const REGION = 1;const REVENUE = 5;
// Sort the cells in place: one undo step, one transaction for collaborators.]);
// Sort the view only: the grid shows the new order, the cells keep their rows.
// The Sort panel (Data › Custom Sort; Excel's Data › Sort): sort levels, a// header row and "Sort view only".
// When the page removes the host: grid.destroy();