A report often shows one set of records several ways: a grid of every record, a pivot by region and status, a second grid grouped by owner, a record panel behind each. Without a dataset every view carries its own copy of the rows, so the page grows with each view, and the browser parses, validates and keeps each copy. A dataset is written once; the views name it, and the browser reads, decodes and validates its rows once and gives every view the same row objects.
Views share rows, not presentation. Each view keeps its own columns (any of the dataset's, with their own titles, formats, presenters and widths), its own query, sort, filters, grouping, pivot, layout and saved state. To filter one view from another as well, use linked views.
var orders = CanopyDataset.Inline("orders");
orders.Columns.Add(new CanopyColumn("region", "region"));
orders.Columns.Add(new CanopyColumn("status", "status"));
orders.Columns.Add(new CanopyColumn("amount", "amount") { Kind = CanopyColumnKind.Number });
foreach (var order in source) orders.Rows.Add(new CanopyGridRow(order.Id) {
Cells = { ["region"] = order.Region, ["status"] = order.Status, ["amount"] = order.Amount }
});
var list = new CanopyDataGridView("order-list", "Orders") { Source = CanopyGridSource.FromDataset(orders) };
list.Columns.Add(new CanopyColumn("region", "Region") { Sortable = true });
list.Columns.Add(new CanopyColumn("amount", "Amount") { Kind = CanopyColumnKind.Number, Sortable = true });
var pivot = new CanopyDataGridView("order-pivot", "Orders by region") { Source = CanopyGridSource.FromDataset(orders) };
// ... columns, reporting aggregates and a pivot, as in pivot.md
orders.ValidateView(list); // optional: early errors for missing or differently typed columns
var document = new CanopyHtmlDocument();
var options = new CanopyHtmlOptions { Document = document };
var html = orders.ToHtmlFragment(options) + list.ToHtmlFragment(options) + pivot.ToHtmlFragment(options);ToHtmlFragment writes a hidden div.cx-dataset element that the runtime reads when the first view queries and never
mounts. Above CanopyRowDataOptions.CompactAboveRows rows it writes compact row data, as a grid does with
its own rows; CanopyHtmlOptions.RowData chooses the format. With inline assets the fragment carries the part that
decodes compact rows. Bundles (SaveBundle) write a grid's own rows into sidecar files; a dataset always travels inside
the page.
Columns declares each cell's id and kind, and the rows are validated against them once. A view's columns must be dataset
columns of the same kind; its titles and everything else are its own.
| Dataset | .NET | Rows |
|---|---|---|
| Inline | CanopyDataset.Inline(id) |
Carried by the page, as row objects or compact chunks. |
| From an address | CanopyDataset.FromUrl(id, url, refresh) |
Read once from a JSON address (an array of rows, or an object with a rows array) for every view, and again every refresh while the page is visible and a view reads them. |
| Hosted | CanopyDataset.Hosted(id) |
None on the page. The page's script registers one host source, which every view uses for its own queries. |
A hosted dataset shares its source, not its rows: each view still sends its own gridQuery with its own view id, so the
host source answers queries for every view that names the dataset. With CanopyX.Data, map one endpoint per view over the
same IQueryable.
CanopyX.defineDataset({ id: "machines", kind: "host", source: { query: (query, options) => myTransport.query(query, options) } });Call it before the views mount. For a hosted dataset the page declares with CanopyDataset.Hosted, the same call gives it
its source.
const orders = CanopyX.defineDataset({
id: "orders",
columns: [{ id: "region", kind: "text" }, { id: "amount", kind: "number" }],
load: async () => readOrders()
});
CanopyX.createDataGrid(listHost, { view: { ...listView, source: { kind: "inline", dataset: "orders" } } });
await orders.ready();
await orders.applyTransaction({ update: [{ id: "order-42", cells: { amount: 125 } }] });
await orders.setRows(next);
await orders.refresh();CanopyX.dataset(id) returns the handle for the current definition. Use either rows, load, or url for a local dataset.
Defining it with load is synchronous. The first reader, ready(), or a transaction starts the load, and concurrent
readers share it. A view's Retry or refresh() can run a failed load again. On a hosted dataset, refresh() asks its
mounted views to query their source again.
CanopyX copies rows supplied to defineDataset, returned by load, or passed to setRows. Set owned: true with
rows or load to transfer the array and its contents without copying. Both ownership modes validate the rows. Leave
transferred rows and anything returned by getRows() unchanged.
applyTransaction({ add, update, remove }) accepts complete rows in add, cell and record changes in update, and ids
in remove. It uses the same ordering and merge rules as grid transactions. The result gives
added, updated, removed, missing, and the dataset revision. An invalid change rejects the whole transaction
before any view or committed row changes. The dataset validates the changed rows and keeps the existing objects for
untouched rows.
Transactions and replacements commit in call order. A transaction waits for the first read and uses the latest committed rows. Readers mounting during a change pick up the resulting revision. An in-flight refresh response is discarded if a newer refresh starts or a transaction or replacement commits first. A transaction that changes no rows leaves the revision alone.
Grids with stable row keys apply their own flash and announcement settings and emit canopyx:rowsChanged. Plain grids
keep the reader's order unless stableOrder is false. Grouped reports and active pivots rebuild their projections.
Board, calendar, and plan follow the same row changes. Ordinal readers query the new revision and clear snapshot-local
selection. setRows replaces the rows and runs each view's query again.
Destroy the readers listed by orders.views() before calling await orders.remove(). Removal rejects while any reader
is mounted, including readers waiting for their first rows. A removed dataset drops its rows, indexes, definition,
and refresh timer. Pending results from its old loader are ignored, and the same id can be defined again.
Use the new handle after redefining the id.
The browser print command reads the mounted view's dataset. For script-free .NET output, pass an explicit
CanopyGridPage to CanopyStaticHtml.RenderGrid(view, page) or RenderGridWithResult. Set the page's view id
to view.Id and include only columns declared by the view. Supply the result order, matching count, and as many
rows as the fallback should show. A static render without a page throws an exception naming the dataset.
Everything that reads rows works as on any inline grid: search, sorting, filters, grouping, totals, pivots, facets, the
record panel and record deep links, linked views, layouts, exports and print. Every committed row change gets a new revision
(dataset-<n>). Ordinal selections and cached summaries belong to the revision that produced them.
Views never write into the rows other views read, so an inline view over a dataset refuses:
- calculated columns, which write their results into the rows;
- editable columns and the editing options;
setRows,addRows,updateRows,removeRowsandapplyTransaction: calldataset.applyTransactionordataset.setRows.
The .NET writer and the runtime both refuse these combinations. A hosted view keeps the live methods of any hosted grid.