Reference visual · full source
Table Power BI custom visual: full source
Table DataView rendered as HTML (no d3): header and row formatting cards.
A hand-written reference visual from the VizForge build server, in the same four files the generator writes and built the same way. It was not generated from a prompt, so there is no prompt to show, and no screenshot of it is stored, so none is shown. Files: capabilities.json (42 lines), visual.ts (201 lines), settings.ts (39 lines), style.less (35 lines).
Data roles
| Field well | Role name | Accepts |
|---|---|---|
| Columns | columns | Field or measure |
DataView mapping: table
Format pane
General (general)
- Show title · Toggle
- Background · Colour picker
Header (header)
- Background · Colour picker
- Font color · Colour picker
- Text size · Number
Rows (rows)
- Text size · Number
- Alternate row · Colour picker
- Negative values · Colour picker
- Show totals · Toggle
Build
- tsc --noEmit
- pass
- pbiviz package
- pass
- pbiviz --certification-audit
- clean
- .pbiviz size
- 6.1 KB
- Build time
- 10 s
Built November 10, 2026with the build server's scripts/build-goldens.sh (powerbi-visuals-tools 7.2.1, TypeScript 5.9.3, powerbi-visuals-api 5.11.1, d3 7.9.0, Node.js 22). Size and time are from that one run.
capabilities.json
Data roles, the DataView mapping and the format-pane objects Power BI reads.
{
"privileges": [],
"dataRoles": [
{ "displayName": "Columns", "name": "columns", "kind": "GroupingOrMeasure" }
],
"dataViewMappings": [
{
"table": {
"rows": { "for": { "in": "columns" }, "dataReductionAlgorithm": { "window": { "count": 1000 } } }
}
}
],
"objects": {
"general": {
"properties": {
"showTitle": { "type": { "bool": true } },
"backgroundColor": { "type": { "fill": { "solid": { "color": true } } } }
}
},
"header": {
"properties": {
"backgroundColor": { "type": { "fill": { "solid": { "color": true } } } },
"fontColor": { "type": { "fill": { "solid": { "color": true } } } },
"fontSize": { "type": { "formatting": { "fontSize": true } } }
}
},
"rows": {
"properties": {
"fontSize": { "type": { "formatting": { "fontSize": true } } },
"alternateRowColor": { "type": { "fill": { "solid": { "color": true } } } },
"negativeColor": { "type": { "fill": { "solid": { "color": true } } } },
"showTotals": { "type": { "bool": true } }
}
}
},
"supportsHighlight": false,
"supportsKeyboardFocus": true,
"supportsMultiVisualSelection": false,
"supportsSynchronizingFilterState": true,
"supportsLandingPage": true,
"sorting": { "default": {} }
}
visual.ts
The IVisual class: constructor, update(), selection, tooltips and the formatting model hook.
"use strict";
import powerbi from "powerbi-visuals-api";
import { FormattingSettingsService } from "powerbi-visuals-utils-formattingmodel";
import { VisualFormattingSettingsModel } from "./settings";
import "./../style/visual.less";
import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
import IVisual = powerbi.extensibility.visual.IVisual;
import IVisualHost = powerbi.extensibility.visual.IVisualHost;
import ISelectionManager = powerbi.extensibility.ISelectionManager;
import ISelectionId = powerbi.visuals.ISelectionId;
import IVisualEventService = powerbi.extensibility.IVisualEventService;
import VisualTooltipDataItem = powerbi.extensibility.VisualTooltipDataItem;
import FormattingModel = powerbi.visuals.FormattingModel;
import DataViewTable = powerbi.DataViewTable;
import PrimitiveValue = powerbi.PrimitiveValue;
interface RowDatum {
cells: PrimitiveValue[];
selectionId: ISelectionId;
}
/** Financial-style table: sticky header, tabular numerals, (negatives) in red, totals row. */
export class Visual implements IVisual {
private host: IVisualHost;
private root: HTMLElement;
private scroller: HTMLElement;
private table: HTMLTableElement;
private selectionManager: ISelectionManager;
private events: IVisualEventService;
private formattingSettingsService = new FormattingSettingsService();
private formattingSettings: VisualFormattingSettingsModel = new VisualFormattingSettingsModel();
private rows: RowDatum[] = [];
private rowEls: HTMLTableRowElement[] = [];
constructor(options: VisualConstructorOptions) {
this.host = options.host;
this.events = this.host.eventService;
this.selectionManager = this.host.createSelectionManager();
this.selectionManager.registerOnSelectCallback((ids: powerbi.extensibility.ISelectionId[]) => this.syncSelectionState(ids as ISelectionId[]));
this.root = options.element;
this.root.classList.add("visual-root", "fin-table");
this.scroller = document.createElement("div");
this.scroller.className = "scroller";
this.table = document.createElement("table");
this.scroller.appendChild(this.table);
this.root.appendChild(this.scroller);
this.root.addEventListener("contextmenu", (event: MouseEvent) => {
this.selectionManager.showContextMenu({}, { x: event.clientX, y: event.clientY });
event.preventDefault();
});
this.scroller.addEventListener("click", () => {
if (!this.host.hostCapabilities.allowInteractions) return;
this.selectionManager.clear().then(() => this.syncSelectionState([]));
});
}
public update(options: VisualUpdateOptions): void {
this.events.renderingStarted(options);
try {
const dv = options.dataViews && options.dataViews[0];
const table = dv?.table;
if (!dv || !table || !table.rows || table.rows.length === 0) {
this.table.replaceChildren();
this.events.renderingFinished(options);
return;
}
this.formattingSettings = this.formattingSettingsService
.populateFormattingSettingsModel<VisualFormattingSettingsModel>(VisualFormattingSettingsModel, dv);
this.rows = table.rows.map((cells, i) => ({
cells,
selectionId: this.host.createSelectionIdBuilder().withTable(table, i).createSelectionId(),
}));
const width = Number(options.viewport.width);
const height = Number(options.viewport.height);
this.root.style.width = `${width}px`;
this.root.style.height = `${height}px`;
if (width < 120 || height < 100) {
this.table.replaceChildren();
} else {
this.render(table, width);
}
} catch (err) {
console.error("[table_visual] update failed", err);
}
this.events.renderingFinished(options);
}
private render(table: DataViewTable, width: number): void {
const s = this.formattingSettings;
this.root.style.background = s.general.backgroundColor.value.value;
this.table.replaceChildren();
this.rowEls = [];
const numeric = table.columns.map((c) => !!(c.type?.numeric || c.type?.integer));
const fontSize = width < 300 ? Math.max(8, Number(s.rows.fontSize.value) - 2) : Number(s.rows.fontSize.value);
const thead = document.createElement("thead");
const hr = document.createElement("tr");
table.columns.forEach((col, ci) => {
const th = document.createElement("th");
th.textContent = col.displayName;
th.className = numeric[ci] ? "num" : "txt";
th.style.background = s.header.backgroundColor.value.value;
th.style.color = s.header.fontColor.value.value;
th.style.fontSize = `${s.header.fontSize.value}px`;
hr.appendChild(th);
});
thead.appendChild(hr);
this.table.appendChild(thead);
const tbody = document.createElement("tbody");
const totals: number[] = table.columns.map(() => 0);
this.rows.forEach((row, ri) => {
const tr = document.createElement("tr");
tr.className = "data-element";
tr.style.fontSize = `${fontSize}px`;
if (ri % 2 === 1) tr.style.background = s.rows.alternateRowColor.value.value;
row.cells.forEach((cell, ci) => {
const td = document.createElement("td");
if (numeric[ci]) {
const n = Number(cell ?? 0);
totals[ci] += isNaN(n) ? 0 : n;
td.className = "num";
td.textContent = this.formatNumber(n);
if (n < 0) td.style.color = s.rows.negativeColor.value.value;
} else {
td.className = "txt";
td.textContent = cell === null || cell === undefined ? "" : String(cell);
}
tr.appendChild(td);
});
this.bindRow(tr, row, table);
tbody.appendChild(tr);
this.rowEls.push(tr);
});
this.table.appendChild(tbody);
if (s.rows.showTotals.value && numeric.some(Boolean)) {
const tfoot = document.createElement("tfoot");
const tr = document.createElement("tr");
tr.className = "grand-total";
tr.style.fontSize = `${fontSize}px`;
table.columns.forEach((_, ci) => {
const td = document.createElement("td");
td.className = numeric[ci] ? "num" : "txt";
td.textContent = numeric[ci] ? this.formatNumber(totals[ci]) : ci === 0 ? "Total" : "";
if (numeric[ci] && totals[ci] < 0) td.style.color = s.rows.negativeColor.value.value;
tr.appendChild(td);
});
tfoot.appendChild(tr);
this.table.appendChild(tfoot);
}
}
private bindRow(tr: HTMLTableRowElement, row: RowDatum, table: DataViewTable): void {
const allow = this.host.hostCapabilities.allowInteractions;
tr.style.cursor = allow ? "pointer" : "default";
tr.addEventListener("click", (event: MouseEvent) => {
if (!allow) return;
this.selectionManager.select(row.selectionId, event.ctrlKey || event.metaKey)
.then((ids: powerbi.extensibility.ISelectionId[]) => this.syncSelectionState(ids as ISelectionId[]));
event.stopPropagation();
});
tr.addEventListener("contextmenu", (event: MouseEvent) => {
this.selectionManager.showContextMenu(row.selectionId, { x: event.clientX, y: event.clientY });
event.preventDefault();
event.stopPropagation();
});
tr.addEventListener("mouseover", (event: MouseEvent) => {
const items: VisualTooltipDataItem[] = table.columns.map((c, i) => ({
displayName: c.displayName,
value: row.cells[i] === null || row.cells[i] === undefined ? "" : String(row.cells[i]),
}));
this.host.tooltipService.show({ coordinates: [event.clientX, event.clientY], isTouchEvent: false, dataItems: items, identities: [row.selectionId] });
});
tr.addEventListener("mousemove", (event: MouseEvent) => {
this.host.tooltipService.move({ coordinates: [event.clientX, event.clientY], isTouchEvent: false, dataItems: [], identities: [] });
});
tr.addEventListener("mouseout", () => this.host.tooltipService.hide({ immediately: true, isTouchEvent: false }));
}
private formatNumber(n: number): string {
if (isNaN(n)) return "";
const abs = Math.abs(n).toLocaleString(undefined, { maximumFractionDigits: 2 });
return n < 0 ? `(${abs})` : abs;
}
private syncSelectionState(ids: ISelectionId[]): void {
const has = ids.length > 0;
this.rowEls.forEach((tr, i) => {
const selected = !has || ids.some((id) => id.equals(this.rows[i].selectionId));
tr.style.opacity = selected ? "1" : "0.3";
});
}
public getFormattingModel(): FormattingModel {
return this.formattingSettingsService.buildFormattingModel(this.formattingSettings);
}
}
settings.ts
The formatting model: one card class per format-pane card, each setting a typed slice.
import { formattingSettings } from "powerbi-visuals-utils-formattingmodel";
import FormattingSettingsCard = formattingSettings.SimpleCard;
import FormattingSettingsSlice = formattingSettings.Slice;
import FormattingSettingsModel = formattingSettings.Model;
class GeneralCard extends FormattingSettingsCard {
showTitle = new formattingSettings.ToggleSwitch({ name: "showTitle", displayName: "Show title", value: true });
backgroundColor = new formattingSettings.ColorPicker({ name: "backgroundColor", displayName: "Background", value: { value: "#FFFFFF" } });
name = "general";
displayName = "General";
slices: FormattingSettingsSlice[] = [this.showTitle, this.backgroundColor];
}
class HeaderCard extends FormattingSettingsCard {
backgroundColor = new formattingSettings.ColorPicker({ name: "backgroundColor", displayName: "Background", value: { value: "#F3F2F1" } });
fontColor = new formattingSettings.ColorPicker({ name: "fontColor", displayName: "Font color", value: { value: "#252423" } });
fontSize = new formattingSettings.NumUpDown({ name: "fontSize", displayName: "Text size", value: 11 });
name = "header";
displayName = "Header";
slices: FormattingSettingsSlice[] = [this.backgroundColor, this.fontColor, this.fontSize];
}
class RowsCard extends FormattingSettingsCard {
fontSize = new formattingSettings.NumUpDown({ name: "fontSize", displayName: "Text size", value: 11 });
alternateRowColor = new formattingSettings.ColorPicker({ name: "alternateRowColor", displayName: "Alternate row", value: { value: "#FAF9F8" } });
negativeColor = new formattingSettings.ColorPicker({ name: "negativeColor", displayName: "Negative values", value: { value: "#A4262C" } });
showTotals = new formattingSettings.ToggleSwitch({ name: "showTotals", displayName: "Show totals", value: true });
name = "rows";
displayName = "Rows";
slices: FormattingSettingsSlice[] = [this.fontSize, this.alternateRowColor, this.negativeColor, this.showTotals];
}
export class VisualFormattingSettingsModel extends FormattingSettingsModel {
general = new GeneralCard();
header = new HeaderCard();
rows = new RowsCard();
cards: FormattingSettingsCard[] = [this.general, this.header, this.rows];
}
style.less
The stylesheet pbiviz compiles into the package.
.visual-root.fin-table {
overflow: hidden;
font-family: "Segoe UI", wf_segoe-ui_normal, helvetica, arial, sans-serif;
color: #252423;
.scroller { width: 100%; height: 100%; overflow: auto; }
table { border-collapse: collapse; width: 100%; }
thead th {
position: sticky;
top: 0;
text-align: left;
padding: 6px 8px;
border-bottom: 1px solid #C8C6C4;
font-weight: 600;
&.num { text-align: right; }
}
td {
padding: 4px 8px;
border-bottom: 1px solid #EDEBE9;
white-space: nowrap;
&.num { text-align: right; font-variant-numeric: tabular-nums; }
}
tbody tr { transition: opacity 0.15s ease; }
tbody tr:hover { background: #F3F2F1; }
tfoot .grand-total td {
font-weight: 600;
border-top: 2.5px solid #605E5C;
border-bottom: 1px solid #605E5C;
}
}
More examples
- Bar chartCartesian chart on a categorical DataView: one category, one measure, axes, gridlines and data labels.
- Donut chartPart-to-whole chart: per-slice colours, a label-style dropdown and a centre label.
- HeatmapMatrix grid: row and column groupings with a colour scale on the value.
- KPI card with sparklineSingle-value card built in HTML: value, target and a trend sparkline by period.
- Multi-series line chartCartesian chart with grouped series: an axis field, a legend field and values, with a legend card.