Chapter 11 of 34

The TableModel: three times three areas

Header, body, footer – each split into west, center and east. The model only answers questions.

After this chapter you can

  • know the nine areas of a table
  • ask an area model for row count and values
  • understand why the model is lazy

Three area models, three sides

A TableModelIf is not a big array. It consists of three area models – header, body and footer (AreaIdent) – plus the column definitions. Fixed columns split every row again into west, center and east (SideIdent). That makes nine areas:

Header, body and footer, each split into west (fixed left), center (scrolls) and east (fixed right) west (fixed) center (scrolls) east (fixed) header header-west header-center header-east body body-west body-center body-east footer footer-west footer-center footer-east fixedLeftColumnCount all other columns – virtual, horizontally and vertically fixedRightColumnCount scrolls
Every area asks its area model: getRowCount(), getValueAt(row, col), getRowHeight(row) …

An area model only answers questions

The table never iterates over your data. It asks the area model – and only for the cells that are visible right now:

That is why the table is fast with any amount of data – and why you can write your own model (chapter 17 (Own AreaModel)).

describe-model.ts
export function describeModel(tableModel: TableModelIf): string {
const header = tableModel.getAreaModel("header");
const body = tableModel.getAreaModel("body");
const footer = tableModel.getAreaModel("footer");
const rows = `${header.getRowCount()} / ${body.getRowCount()} / ${footer.getRowCount()}`;
const firstCustomer = body.getValueAt(0, 2); // row 0, column 2
const left = tableModel.getFixedLeftColumnCount();
const right = tableModel.getFixedRightColumnCount();
return `rows (header/body/footer): ${rows} · ${tableModel.getColumnCount()} columns · ` +
`fixed west/east: ${left}/${right} · first customer: ${firstCustomer}`;
}

See the nine areas

The demo colours every area differently: ID is fixed on the left (west), status on the right (east), a footer row at the bottom.

const tableModel = TableFactory.createTableModel({
rows: orders,
properties: ["id", "date", "customer", "country", "city", "product", "quantity", "price", "total", "status"],
footerData: [["Σ", "", `${orders.length} orders`, "", "", "", "", "", "", ""]],
fixedLeftColumnCount: 1, // west: ID
fixedRightColumnCount: 1 // east: status
});
Live Nine areas
Screenshot: Nine areas Screenshot: Nine areas
Scroll horizontally: west and east stay, center moves. Scroll vertically: header and footer stay, body moves.

Which classes do what?

TypeUse it forChapter
AreaModelObjectArrayan array of objects – what TableFactory creates for rows12
AreaModelArrayOfArraysrows as arrays (CSV, matrices)14
AreaModelCellGroupsgrouped, collapsible headers15
AreaModelbase class for your own models (footers, millions of rows, server data)16, 17
AreaModelTreetree tables30

Next

The most common case first: an array of typed objects becomes a table – chapter 12 (Array<T> → model).

API used in this chapter