@motifx-community/ui 0.1.0-beta.14 → 0.1.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +113 -0
- package/README.md +2 -2
- package/dist/components/diagram/Diagram.d.ts +607 -0
- package/dist/components/diagram/DiagramAutoPan.d.ts +17 -0
- package/dist/components/diagram/DiagramBends.d.ts +70 -0
- package/dist/components/diagram/DiagramDragging.d.ts +66 -0
- package/dist/components/diagram/DiagramEdgeView.d.ts +78 -0
- package/dist/components/diagram/DiagramGrid.d.ts +13 -0
- package/dist/components/diagram/DiagramHistory.d.ts +16 -0
- package/dist/components/diagram/DiagramLinks.d.ts +177 -0
- package/dist/components/diagram/DiagramMap.d.ts +62 -0
- package/dist/components/diagram/DiagramNodeView.d.ts +143 -0
- package/dist/components/diagram/DiagramOverview.d.ts +20 -0
- package/dist/components/diagram/DiagramPanning.d.ts +34 -0
- package/dist/components/diagram/diagram-alignment.d.ts +2 -0
- package/dist/components/diagram/diagram-auto-pan-host.d.ts +8 -0
- package/dist/components/diagram/diagram-background.d.ts +2 -0
- package/dist/components/diagram/diagram-bends-host.d.ts +17 -0
- package/dist/components/diagram/diagram-card-kind.d.ts +42 -0
- package/dist/components/diagram/diagram-card-node.d.ts +11 -0
- package/dist/components/diagram/diagram-center-options.d.ts +6 -0
- package/dist/components/diagram/diagram-change.d.ts +11 -0
- package/dist/components/diagram/diagram-class-member.d.ts +13 -0
- package/dist/components/diagram/diagram-class-node.d.ts +12 -0
- package/dist/components/diagram/diagram-column-checked-event-args.d.ts +9 -0
- package/dist/components/diagram/diagram-connected-event-args.d.ts +6 -0
- package/dist/components/diagram/diagram-connecting-event-args.d.ts +9 -0
- package/dist/components/diagram/diagram-connection.d.ts +7 -0
- package/dist/components/diagram/diagram-data.d.ts +12 -0
- package/dist/components/diagram/diagram-deleted-event-args.d.ts +8 -0
- package/dist/components/diagram/diagram-deleting-event-args.d.ts +9 -0
- package/dist/components/diagram/diagram-dragging-host.d.ts +47 -0
- package/dist/components/diagram/diagram-drawn-node.d.ts +10 -0
- package/dist/components/diagram/diagram-edge-end.d.ts +2 -0
- package/dist/components/diagram/diagram-edge-path.d.ts +5 -0
- package/dist/components/diagram/diagram-edge-reshaped-event-args.d.ts +8 -0
- package/dist/components/diagram/diagram-edge-reshaping-event-args.d.ts +6 -0
- package/dist/components/diagram/diagram-edge.d.ts +49 -0
- package/dist/components/diagram/diagram-edit.d.ts +10 -0
- package/dist/components/diagram/diagram-export-options.d.ts +14 -0
- package/dist/components/diagram/diagram-export.d.ts +28 -0
- package/dist/components/diagram/diagram-fit-options.d.ts +12 -0
- package/dist/components/diagram/diagram-history-changed-event-args.d.ts +14 -0
- package/dist/components/diagram/diagram-history-step.d.ts +9 -0
- package/dist/components/diagram/diagram-kinds.d.ts +9 -0
- package/dist/components/diagram/diagram-layered.d.ts +39 -0
- package/dist/components/diagram/diagram-layout-direction.d.ts +2 -0
- package/dist/components/diagram/diagram-layout-options.d.ts +24 -0
- package/dist/components/diagram/diagram-layout-type.d.ts +5 -0
- package/dist/components/diagram/diagram-layout.d.ts +33 -0
- package/dist/components/diagram/diagram-line-look.d.ts +6 -0
- package/dist/components/diagram/diagram-line.d.ts +11 -0
- package/dist/components/diagram/diagram-links-host.d.ts +45 -0
- package/dist/components/diagram/diagram-links-options.d.ts +7 -0
- package/dist/components/diagram/diagram-map-props.d.ts +10 -0
- package/dist/components/diagram/diagram-map-target.d.ts +27 -0
- package/dist/components/diagram/diagram-marker.d.ts +6 -0
- package/dist/components/diagram/diagram-mini-map-options.d.ts +13 -0
- package/dist/components/diagram/diagram-mini-map-position.d.ts +2 -0
- package/dist/components/diagram/diagram-node-context.d.ts +26 -0
- package/dist/components/diagram/diagram-node-host.d.ts +23 -0
- package/dist/components/diagram/diagram-node-kind.d.ts +43 -0
- package/dist/components/diagram/diagram-node-move.d.ts +11 -0
- package/dist/components/diagram/diagram-node-resized-event-args.d.ts +8 -0
- package/dist/components/diagram/diagram-node-resizing-event-args.d.ts +6 -0
- package/dist/components/diagram/diagram-node-size.d.ts +8 -0
- package/dist/components/diagram/diagram-node-status.d.ts +2 -0
- package/dist/components/diagram/diagram-node-toggled-event-args.d.ts +7 -0
- package/dist/components/diagram/diagram-node.d.ts +56 -0
- package/dist/components/diagram/diagram-nodes-moved-event-args.d.ts +6 -0
- package/dist/components/diagram/diagram-nodes-moving-event-args.d.ts +6 -0
- package/dist/components/diagram/diagram-panning-host.d.ts +19 -0
- package/dist/components/diagram/diagram-pasted-event-args.d.ts +7 -0
- package/dist/components/diagram/diagram-pasting-event-args.d.ts +11 -0
- package/dist/components/diagram/diagram-path-ends.d.ts +11 -0
- package/dist/components/diagram/diagram-path-result.d.ts +6 -0
- package/dist/components/diagram/diagram-paths.d.ts +35 -0
- package/dist/components/diagram/diagram-point.d.ts +5 -0
- package/dist/components/diagram/diagram-port-place.d.ts +9 -0
- package/dist/components/diagram/diagram-port.d.ts +27 -0
- package/dist/components/diagram/diagram-props.d.ts +159 -0
- package/dist/components/diagram/diagram-reconnected-event-args.d.ts +10 -0
- package/dist/components/diagram/diagram-reconnecting-event-args.d.ts +11 -0
- package/dist/components/diagram/diagram-rect.d.ts +7 -0
- package/dist/components/diagram/diagram-resize-side.d.ts +2 -0
- package/dist/components/diagram/diagram-route.d.ts +10 -0
- package/dist/components/diagram/diagram-selection-changed-event-args.d.ts +9 -0
- package/dist/components/diagram/diagram-selection.d.ts +5 -0
- package/dist/components/diagram/diagram-side.d.ts +2 -0
- package/dist/components/diagram/diagram-table-column.d.ts +13 -0
- package/dist/components/diagram/diagram-table-node.d.ts +12 -0
- package/dist/components/diagram/diagram-tree.d.ts +14 -0
- package/dist/components/diagram/diagram-viewport-changed-event-args.d.ts +8 -0
- package/dist/components/diagram/diagram-viewport-options.d.ts +5 -0
- package/dist/components/diagram/diagram-viewport.d.ts +6 -0
- package/dist/components/diagram/index.d.ts +65 -0
- package/dist/components/diagram/swallow-next-click.d.ts +5 -0
- package/dist/components/expressioneditor/ExpressionEditor.d.ts +111 -0
- package/dist/components/expressioneditor/expression-editor-props.d.ts +24 -0
- package/dist/components/expressioneditor/index.d.ts +2 -0
- package/dist/components/formlayout/FormLayout.d.ts +10 -3
- package/dist/components/formlayout/form-editor-type.d.ts +1 -1
- package/dist/components/formlayout/form-item.d.ts +4 -1
- package/dist/components/formlayout/form-layout-props.d.ts +1 -1
- package/dist/components/formlayout/index.d.ts +1 -0
- package/dist/components/formlayout/schema-items.d.ts +26 -0
- package/dist/components/pivotgrid/model/PivotAxisWindow.d.ts +53 -1
- package/dist/components/pivotgrid/model/PivotCellWindow.d.ts +2 -0
- package/dist/components/pivotgrid/model/PivotWindows.d.ts +3 -6
- package/dist/components/toolbar/Toolbar.d.ts +5 -3
- package/dist/core/control.d.ts +2 -0
- package/dist/core/keyboard.d.ts +5 -0
- package/dist/core/measure/index.d.ts +2 -0
- package/dist/core/measure/picture.d.ts +27 -0
- package/dist/core/shortcut-options.d.ts +5 -2
- package/dist/core/ui-strings.d.ts +191 -0
- package/dist/generated/tokens.d.ts +1615 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11501 -705
- package/dist/index.js.map +1 -1
- package/dist/locales/en.json +180 -1
- package/dist/locales/tr.json +180 -1
- package/dist/styles.css +2262 -3
- package/dist/tokens/index.d.ts +1615 -0
- package/dist/tokens/index.js +1615 -0
- package/dist/tokens/index.js.map +1 -1
- package/dist/{tr-BGbF9uCs.js → tr-4GNbFdQh.js} +361 -3
- package/dist/{tr-BGbF9uCs.js.map → tr-4GNbFdQh.js.map} +1 -1
- package/docs/accordion.md +1 -1
- package/docs/actionsheet.md +1 -1
- package/docs/appbar.md +1 -1
- package/docs/appmenu-api.md +1 -1
- package/docs/appmenu-programmatic.md +1 -1
- package/docs/appmenu-search.md +1 -1
- package/docs/appmenu.md +1 -1
- package/docs/avatar.md +1 -1
- package/docs/badge.md +1 -1
- package/docs/bar-gauge-angles.md +1 -1
- package/docs/bar-gauge-data.md +1 -1
- package/docs/bar-gauge-labels.md +1 -1
- package/docs/bar-gauge.md +1 -1
- package/docs/barcode.md +1 -1
- package/docs/bottomnavigation.md +1 -1
- package/docs/bottomsheet.md +1 -1
- package/docs/breadcrumb.md +1 -1
- package/docs/button.md +1 -1
- package/docs/buttongroup.md +1 -1
- package/docs/buttons.md +1 -1
- package/docs/calendar.md +1 -1
- package/docs/card.md +1 -1
- package/docs/chart-bars.md +1 -1
- package/docs/chart-candles.md +1 -1
- package/docs/chart-funnel.md +1 -1
- package/docs/chart-heatmap.md +1 -1
- package/docs/chart-lines.md +1 -1
- package/docs/chart-live.md +1 -1
- package/docs/chart-pie.md +1 -1
- package/docs/chart-radar.md +1 -1
- package/docs/chart-ranges.md +1 -1
- package/docs/chart-references.md +1 -1
- package/docs/chart-scatter.md +1 -1
- package/docs/chart-waterfall.md +1 -1
- package/docs/chart-zoom.md +1 -1
- package/docs/chart.md +1 -1
- package/docs/chat.md +1 -1
- package/docs/checkbox.md +1 -1
- package/docs/chip.md +1 -1
- package/docs/choice.md +1 -1
- package/docs/colorbox.md +1 -1
- package/docs/combobox.md +1 -1
- package/docs/commands.md +1 -1
- package/docs/control.md +1 -1
- package/docs/data.md +2 -2
- package/docs/datagrid-api.md +1 -1
- package/docs/datagrid-bands.md +1 -1
- package/docs/datagrid-drag-select.md +1 -1
- package/docs/datagrid-drag.md +1 -1
- package/docs/datagrid-editing.md +1 -1
- package/docs/datagrid-filtering.md +1 -1
- package/docs/datagrid-forms.md +1 -1
- package/docs/datagrid-grouping.md +1 -1
- package/docs/datagrid-layout.md +1 -1
- package/docs/datagrid-lookups.md +1 -1
- package/docs/datagrid-master-detail.md +1 -1
- package/docs/datagrid-scrolling.md +1 -1
- package/docs/datagrid-selection.md +1 -1
- package/docs/datagrid.md +1 -1
- package/docs/datalayer-api.md +491 -0
- package/docs/datalayer-changes.md +501 -0
- package/docs/datalayer-odata.md +998 -0
- package/docs/datalayer-pivot.md +850 -0
- package/docs/datalayer-queries.md +516 -0
- package/docs/datalayer-rest.md +529 -0
- package/docs/datalayer-soap.md +576 -0
- package/docs/datalayer-source.md +464 -0
- package/docs/datalayer.md +264 -0
- package/docs/datebox.md +1 -1
- package/docs/daterangebox.md +1 -1
- package/docs/diagram-api.md +200 -0
- package/docs/diagram-commands.md +79 -0
- package/docs/diagram-connections.md +157 -0
- package/docs/diagram-custom-nodes.md +325 -0
- package/docs/diagram-designer.md +816 -0
- package/docs/diagram-editing.md +62 -0
- package/docs/diagram-flow.md +157 -0
- package/docs/diagram-keyboard.md +58 -0
- package/docs/diagram-layout.md +354 -0
- package/docs/diagram-nodes.md +206 -0
- package/docs/diagram-tables.md +212 -0
- package/docs/diagram.md +217 -0
- package/docs/display.md +1 -1
- package/docs/draggable.md +1 -1
- package/docs/drawer.md +1 -1
- package/docs/dropdown.md +1 -1
- package/docs/editors.md +1 -1
- package/docs/expressioneditor.md +469 -0
- package/docs/expressions.md +431 -0
- package/docs/feedback.md +1 -1
- package/docs/fileuploader.md +1 -1
- package/docs/filterbuilder.md +1 -1
- package/docs/formlayout-schema.md +143 -0
- package/docs/formlayout.md +16 -4
- package/docs/foundations.md +1 -1
- package/docs/gallery.md +1 -1
- package/docs/gauge-base.md +1 -1
- package/docs/gauge-circular.md +1 -1
- package/docs/gauge-dashboards.md +1 -1
- package/docs/gauge-linear.md +1 -1
- package/docs/gauge-markers.md +1 -1
- package/docs/gauge-marks.md +1 -1
- package/docs/gauge-ranges.md +1 -1
- package/docs/gauge-scales.md +1 -1
- package/docs/gauge.md +1 -1
- package/docs/home.md +1 -1
- package/docs/keyboard.md +2 -2
- package/docs/language.md +1 -1
- package/docs/layout.md +1 -1
- package/docs/listbox.md +1 -1
- package/docs/loadpanel.md +1 -1
- package/docs/lookup.md +1 -1
- package/docs/markdown.md +1 -1
- package/docs/menus-api.md +1 -1
- package/docs/menus-context.md +1 -1
- package/docs/menus-customization.md +1 -1
- package/docs/menus-merging.md +1 -1
- package/docs/menus-programmatic.md +1 -1
- package/docs/menus.md +1 -1
- package/docs/multiview.md +1 -1
- package/docs/navigation.md +1 -1
- package/docs/numberbox.md +1 -1
- package/docs/otpinput.md +1 -1
- package/docs/pagination.md +1 -1
- package/docs/pivotgrid-api.md +1 -1
- package/docs/pivotgrid-chart.md +1 -1
- package/docs/pivotgrid-drilldown.md +1 -1
- package/docs/pivotgrid-export.md +1 -1
- package/docs/pivotgrid-fields.md +1 -1
- package/docs/pivotgrid-keyboard.md +1 -1
- package/docs/pivotgrid-layout.md +1 -1
- package/docs/pivotgrid-panel.md +1 -1
- package/docs/pivotgrid-remote.md +122 -44
- package/docs/pivotgrid-sorting.md +3 -3
- package/docs/pivotgrid-state.md +1 -1
- package/docs/pivotgrid-summaries.md +1 -1
- package/docs/pivotgrid.md +1 -1
- package/docs/popover.md +1 -1
- package/docs/progress.md +1 -1
- package/docs/qrcode.md +1 -1
- package/docs/radiogroup.md +1 -1
- package/docs/rating.md +1 -1
- package/docs/resizable.md +1 -1
- package/docs/ribbonmenu-api.md +1 -1
- package/docs/ribbonmenu-commands.md +1 -1
- package/docs/ribbonmenu-customization.md +1 -1
- package/docs/ribbonmenu-display.md +1 -1
- package/docs/ribbonmenu-layouts.md +1 -1
- package/docs/ribbonmenu-programmatic.md +1 -1
- package/docs/ribbonmenu.md +1 -1
- package/docs/scheduler-agenda.md +1 -1
- package/docs/scheduler-big-data.md +1 -1
- package/docs/scheduler-editing.md +1 -1
- package/docs/scheduler-form.md +1 -1
- package/docs/scheduler-icalendar.md +1 -1
- package/docs/scheduler-mobile.md +1 -1
- package/docs/scheduler-recurrence.md +1 -1
- package/docs/scheduler-resources.md +1 -1
- package/docs/scheduler-timeline.md +1 -1
- package/docs/scheduler.md +1 -1
- package/docs/scrollview.md +1 -1
- package/docs/shortcuteditor.md +1 -1
- package/docs/showcase-flowstudio.md +61 -0
- package/docs/showcase-home.md +1 -1
- package/docs/showcase-mail.md +1 -1
- package/docs/showcase.md +1 -1
- package/docs/signature.md +1 -1
- package/docs/skeleton.md +1 -1
- package/docs/slider.md +1 -1
- package/docs/sortable.md +1 -1
- package/docs/sparkline.md +1 -1
- package/docs/speeddial.md +1 -1
- package/docs/splitter.md +1 -1
- package/docs/stepper.md +1 -1
- package/docs/switch.md +1 -1
- package/docs/tabdocs-dock.md +1 -1
- package/docs/tabdocs-drag.md +1 -1
- package/docs/tabdocs-menus.md +1 -1
- package/docs/tabdocs-mobile.md +1 -1
- package/docs/tabdocs-tabs.md +1 -1
- package/docs/tabdocs-windows.md +1 -1
- package/docs/tabdocs-workspace.md +1 -1
- package/docs/tabdocs.md +1 -1
- package/docs/tabs.md +1 -1
- package/docs/tagbox.md +1 -1
- package/docs/textarea.md +1 -1
- package/docs/textbox.md +1 -1
- package/docs/tileview.md +1 -1
- package/docs/timeline.md +1 -1
- package/docs/toast.md +1 -1
- package/docs/tokens.md +324 -1
- package/docs/toolbar-api.md +1 -1
- package/docs/toolbar-customization.md +1 -1
- package/docs/toolbar.md +1 -1
- package/docs/tooltip.md +1 -1
- package/docs/treeview.md +1 -1
- package/docs/validationsummary.md +1 -1
- package/docs/window.md +1 -1
- package/docs/wizard.md +1 -1
- package/llms-full.txt +10142 -462
- package/llms.txt +32 -1
- package/package.json +2 -2
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
# Data layer: Filtering, sorting and grouping
|
|
2
|
+
|
|
3
|
+
> Data layer · @motifx-community/data 0.1.0-beta.3
|
|
4
|
+
|
|
5
|
+
Every adapter takes the same query, `LoadOptions` (a filter, a sort order, a page, the fields to select, grouping levels and summaries), and answers it with a `LoadResult`. This page describes each part of the query, the filter format the whole kit shares, and the memory engine that runs a query over rows in the browser.
|
|
6
|
+
|
|
7
|
+
## Filters as data
|
|
8
|
+
|
|
9
|
+
A filter is plain data: a condition `{ field, op, value }`, or `and`, `or` and `not` of other filters. Because it is data, it can be kept in state, stored and sent, and every adapter translates it for its backend (the REST adapter sends it as JSON, the OData adapter writes `$filter`) or applies it in memory where the backend cannot filter. The builders under `data` produce the same objects:
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { data } from '@motifx-community/data';
|
|
13
|
+
|
|
14
|
+
const filter = data.and(
|
|
15
|
+
data.where('city', '=', 'Ankara'),
|
|
16
|
+
data.or(data.where('amount', '>=', 100), data.where('product', '=', 'Desk')),
|
|
17
|
+
data.not(data.where('customer', 'startswith', 'test')),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// The same filter as data:
|
|
21
|
+
// { and: [
|
|
22
|
+
// { field: 'city', op: '=', value: 'Ankara' },
|
|
23
|
+
// { or: [{ field: 'amount', op: '>=', value: 100 }, { field: 'product', op: '=', value: 'Desk' }] },
|
|
24
|
+
// { not: { field: 'customer', op: 'startswith', value: 'test' } },
|
|
25
|
+
// ] }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
[FilterBuilder](filterbuilder.md) is the kit's component that builds these filters, as a user edits conditions. The [expression language](expressions.md) is a different thing: it computes values and rules from text, while a filter is a data structure every backend can run.
|
|
29
|
+
|
|
30
|
+
### Operators
|
|
31
|
+
|
|
32
|
+
Text compares without case in the adapter's locale unless the condition sets `caseSensitive`; [How values compare](#comparison) gives the rules.
|
|
33
|
+
|
|
34
|
+
| Operator | Meaning |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `=` | Equal. With an empty value it matches the rows whose field is blank, as `isblank` does. |
|
|
37
|
+
| `<>` | Not equal. With an empty value it matches the rows whose field is not blank, as `isnotblank` does. |
|
|
38
|
+
| `< <= > >=` | Order, by the field's type: numbers, dates by day or moment, text in the locale's collation. A blank row value never matches, and with an empty condition value nothing matches. |
|
|
39
|
+
| `contains` | The value stands somewhere in the field's text. An empty value filters nothing out, like an empty filter box. |
|
|
40
|
+
| `notcontains` | The value stands nowhere in the field's text. An empty value filters nothing out. |
|
|
41
|
+
| `startswith` | The field's text starts with the value. |
|
|
42
|
+
| `endswith` | The field's text ends with the value. |
|
|
43
|
+
| `between` | The field is inside `[from, to]`, both ends included; a `null` end leaves that side open. |
|
|
44
|
+
| `in` | The field equals one of the values of an array; an empty value among them matches blank rows. |
|
|
45
|
+
| `notin` | The field equals none of the values of an array. |
|
|
46
|
+
| `isblank` | The field is blank (see below); the condition takes no value. |
|
|
47
|
+
| `isnotblank` | The field is not blank; the condition takes no value. |
|
|
48
|
+
|
|
49
|
+
### Fields that hold several values
|
|
50
|
+
|
|
51
|
+
A field may hold an array of values, such as the tags of an article. A condition matches the row when one of the values matches; with a negative operator (`<>`, `notin`, `notcontains`), when none of them does.
|
|
52
|
+
|
|
53
|
+
### Blank values
|
|
54
|
+
|
|
55
|
+
`isblank` matches `null`, `undefined`, `NaN` and text of only spaces. A field that holds an array is blank when no value in it is other than blank; an empty array is blank too. `=` with an empty value asks the same question, and `<>` with an empty value matches the rest, so a condition whose editor was left empty behaves as a blank test. The text operators with an empty value filter nothing out instead, like an empty filter box.
|
|
56
|
+
|
|
57
|
+
### Conditions through an interval
|
|
58
|
+
|
|
59
|
+
A condition with an `interval` compares the value the interval reads, as [a pivot level](datalayer-pivot.md) groups it: a part of a date (`'year'`, `'quarter'`, `'month'`, `'day'`, `'dayOfWeek'` or `'date'`, the calendar day), or ranges of numbers of a given width, each named by its start. A value the interval cannot read is blank. The OData adapter writes date intervals with its date functions.
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
// Orders of 2026, whatever the day:
|
|
63
|
+
data.where('orderedOn', '=', 2026, { interval: 'year' });
|
|
64
|
+
// Amounts of 100 up to but not including 150 (ranges of 50, named by their start):
|
|
65
|
+
data.where('amount', '=', 100, { interval: 50 });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Filters a backend cannot write
|
|
69
|
+
|
|
70
|
+
`adapter.canFilter(filter)` indicates whether the backend applies a filter. The base adapter answers `true` for every filter; the OData adapter answers `false` for one its query language cannot write, such as a condition on the day of the week, which OData has no function for. Such a filter is left to the caller, who loads the rows without it and filters them in memory with `createRowFilter`.
|
|
71
|
+
|
|
72
|
+
### Helpers
|
|
73
|
+
|
|
74
|
+
| Function | Returns | Description |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `data.where(field, op, value?, options?)` | `FilterCondition` | One condition. `options` compares text with case (`{ caseSensitive: true }`, or `true` alone) or compares the field through an `interval`. |
|
|
77
|
+
| `data.and(...filters) data.or(...filters)` | `FilterExpression \| null` | Joins filters. Arguments that are `null` or `undefined` are left out, a single remaining argument is returned as it is, and nothing left gives `null`, so optional conditions join without checks. |
|
|
78
|
+
| `data.not(filter)` | `FilterExpression` | The rows the filter does not match. |
|
|
79
|
+
| `data.none()` | `FilterExpression` | A filter no row passes (an `or` of nothing): a search that matched no field. |
|
|
80
|
+
| `data.isCondition(filter)` | `boolean` | Whether a filter expression is a single condition; a type guard for code that walks an expression. |
|
|
81
|
+
| `data.isFilterExpression(value)` | `boolean` | Whether a value is a filter expression: a condition with a known operator, or `and`, `or`, `not` of them. |
|
|
82
|
+
| `data.fieldsInFilter(filter)` | `Set<string>` | The names of the fields the filter reads. |
|
|
83
|
+
| `data.validateFilter(value)` | `void` | Throws a `TypeError` that names the place and the problem when the value is not a filter expression. Adapters validate the filter of every load and reject a wrong one with `MJD302`. |
|
|
84
|
+
| `data.createRowFilter(filter, context?)` | `(row) => boolean` | A function that tests a row against the filter, for filtering in memory. A field without a declared type takes the type of the condition's value. |
|
|
85
|
+
|
|
86
|
+
## How values compare
|
|
87
|
+
|
|
88
|
+
The memory engine compares two values by the field's type: numbers as numbers, `date` fields by calendar day, `datetime` fields by moment, `guid` ids without case, booleans with `false` before `true`, and everything else as text. The type comes from the adapter's `fields` option; a field without a declared type takes the type of the value it meets: the condition's value when filtering, the first value that is not empty when sorting or grouping.
|
|
89
|
+
|
|
90
|
+
Text compares in the adapter's `locale`, without case unless the condition sets `caseSensitive`; with `locale: 'tr'`, `'izmir'` matches `'İzmir'`. Digits inside text compare as numbers, so `'order 2'` sorts before `'order 10'`. A `date` field also reads a `'2026-03-01'` text as that calendar day, the way a date editor writes it.
|
|
91
|
+
|
|
92
|
+
Three adapter options change what memory reads and compares for a particular field. Each is called once per field and returns a function for the fields it covers, `undefined` for the rest:
|
|
93
|
+
|
|
94
|
+
| Option | Description |
|
|
95
|
+
| --- | --- |
|
|
96
|
+
| `fields` | The declared type of each field: `'string'`, `'number'`, `'boolean'`, `'date'` (a calendar day, compared by day), `'datetime'` (a moment) or `'guid'` (an id, compared without case). |
|
|
97
|
+
| `locale` | The locale text is compared in, in memory: its case rules and its collation. With `locale: 'tr'`, `İ` matches `i` and `I` matches `ı`. |
|
|
98
|
+
| `filterValue` | Filtering in memory reads the field with this function instead (a computed value); `undefined` for the field's own value. |
|
|
99
|
+
| `sortValue` | Sorting in memory reads the field with this function instead (a computed value); `undefined` for the field's own value. |
|
|
100
|
+
| `compare` | Sorting in memory compares the field's values with this function instead of the type rules; empty values still go last. |
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
const RANK: Record<string, number> = { ordered: 0, shipped: 1, delivered: 2 };
|
|
104
|
+
|
|
105
|
+
const orders = new data.ArrayAdapter<Order, number>({
|
|
106
|
+
data: rows,
|
|
107
|
+
key: 'id',
|
|
108
|
+
locale: 'tr',
|
|
109
|
+
fields: { orderedOn: 'date', amount: 'number' },
|
|
110
|
+
// Filtering and sorting read the full name, a value the rows do not hold:
|
|
111
|
+
filterValue: (field) => (field === 'customer' ? (row) => `${row.firstName} ${row.lastName}` : undefined),
|
|
112
|
+
sortValue: (field) => (field === 'customer' ? (row) => `${row.lastName} ${row.firstName}` : undefined),
|
|
113
|
+
// The status sorts by rank, not by its text:
|
|
114
|
+
compare: (field) => (field === 'status' ? (a, b) => RANK[a as string] - RANK[b as string] : undefined),
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
These options reach only the work done in memory. A backend that filters or sorts itself never sees them, so a field a backend cannot compute is paired with `capabilities` that move its work into memory; see [Where the work runs](#engine).
|
|
119
|
+
|
|
120
|
+
## Sorting
|
|
121
|
+
|
|
122
|
+
`sort` is a list of `{ field, dir }` items, applied in order: rows equal in the first item are ordered by the second. `dir` is `'asc'` or `'desc'`. The sort is stable, so rows equal in every item keep the order the backend returned them in, and a dotted `field` reads a nested value (`'customer.name'`).
|
|
123
|
+
|
|
124
|
+
Empty values (`null`, `undefined`, `''`, `NaN`) go last, whatever the direction. Other values compare as [the field's type says](#comparison), and `sortValue` and `compare` change what a field sorts by. `data.sortRows(rows, sort, context)` sorts an array with the same rules, without the rest of a query.
|
|
125
|
+
|
|
126
|
+
## Paging, counting and selecting fields
|
|
127
|
+
|
|
128
|
+
`skip` and `take` cut the page out of the matching rows, after filtering and sorting. Both are numbers of 0 or more, fractions floored; anything else fails the load with `MJD302`. With `count: true` the result also carries `total`, the number of matching rows without the paging; it is the number a pager shows. When the query groups, `skip` and `take` count top-level groups instead, and `count` also fills `groupCount`; see [Groups](#groups).
|
|
129
|
+
|
|
130
|
+
`select` names the fields the rows of the result hold; a dotted path reaches a nested field and is written back at the same place. Without `select`, the `ArrayAdapter` returns the row objects themselves; with it, every row of the result is a new object of the selected fields alone. `data.pickFields(row, fields)` picks the same way from one row.
|
|
131
|
+
|
|
132
|
+
`expand` names related data to include with each row. The concept is OData's `$expand` ([OData](datalayer-odata.md)); the REST adapter's default query passes the list on as `expand`, and a backend without the concept ignores it. `params` go to the backend as they are, for values of your own, and `signal` cancels the load: a cancelled load rejects with `MJD105`.
|
|
133
|
+
|
|
134
|
+
## Build a query
|
|
135
|
+
|
|
136
|
+
The playground below runs a query over 240 invented orders in an `ArrayAdapter`, every 19th without a city. The editors build one or two conditions, a sort and a page; under them stand the load as code, the filter as the data it stands for, and the rows and `total` the load resolves to. The blank tests, empty values and the `amount` ranges of the sections above can all be tried here.
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
/** An order of the examples on this page. */
|
|
140
|
+
export interface Order {
|
|
141
|
+
id: number;
|
|
142
|
+
customer: string;
|
|
143
|
+
city: string | null;
|
|
144
|
+
product: string;
|
|
145
|
+
orderedOn: string;
|
|
146
|
+
amount: number;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const CUSTOMERS = ['Elif Demir', 'Can Yılmaz', 'Zeynep Kaya', 'Mert Şahin', 'Ayşe Çelik', 'Deniz Arslan', 'Burak Koç', 'Selin Aydın'];
|
|
150
|
+
const CITIES = ['Ankara', 'Bursa', 'İstanbul', 'İzmir', 'Konya', 'Trabzon'];
|
|
151
|
+
const PRODUCTS = ['Desk', 'Chair', 'Lamp', 'Shelf', 'Monitor', 'Keyboard'];
|
|
152
|
+
|
|
153
|
+
/** `n` orders, the same ones every time; every 19th has no city, so blank values can be tried. */
|
|
154
|
+
export function makeOrders(n = 240): Order[] {
|
|
155
|
+
const day = Date.UTC(2026, 0, 1);
|
|
156
|
+
return Array.from({ length: n }, (_, i) => ({
|
|
157
|
+
id: i + 1,
|
|
158
|
+
customer: CUSTOMERS[(i * 5) % CUSTOMERS.length],
|
|
159
|
+
city: i % 19 === 0 ? null : CITIES[(i * 7) % CITIES.length],
|
|
160
|
+
product: PRODUCTS[Math.floor(i / 6) % PRODUCTS.length],
|
|
161
|
+
orderedOn: new Date(day + ((i * 37) % 300) * 86_400_000).toISOString().slice(0, 10),
|
|
162
|
+
amount: 40 + ((i * 7919) % 90_000) / 100,
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Groups
|
|
168
|
+
|
|
169
|
+
`group` names grouping levels: rows with the same value of `field` form a group, and groups are ordered by that value (`dir`, `'asc'` by default). The result's `groups` holds one `RowGroup` per group of the first level: its `field`, its `key`, its `count` of rows with all levels below included, and either its rows in `items` (on the last level) or the groups of the next level in `groups`. The result's `rows` holds the same rows flat, in group order, and the query's `sort` orders them inside the groups.
|
|
170
|
+
|
|
171
|
+
Values group the way filters compare them: text without case in the locale, declared `date` fields by day. The key keeps the value as the first row of the group holds it. Empty values form one group whose key is `null`, ordered last whatever the direction.
|
|
172
|
+
|
|
173
|
+
With `group`, `skip` and `take` page by top-level groups, each page carrying whole groups with their rows, and `count` fills `groupCount` with the number of top-level groups, next to `total` with the number of rows. `groupsOnly: true` answers with the groups, their counts and their `groupSummary` alone and leaves `rows` empty, for a view that opens closed groups on demand.
|
|
174
|
+
|
|
175
|
+
## Summaries
|
|
176
|
+
|
|
177
|
+
`summary` computes values over every matching row, not only the page; `groupSummary` computes its items for every group, at every level. An item is `{ type, field }`, and the values come back in item order: the query's in the result's `summary`, a group's in its own `summary`.
|
|
178
|
+
|
|
179
|
+
| Type | Meaning |
|
|
180
|
+
| --- | --- |
|
|
181
|
+
| `count` | The number of rows. It reads no field, so the item needs none. |
|
|
182
|
+
| `countDistinct` | The number of different values that are not empty, compared the way filters compare them: text without case in the locale, `date` fields by day. Over no values it is 0. |
|
|
183
|
+
| `sum avg` | Read numbers; a value that does not read as a number is left out. Over no values, `sum` is 0 and `avg` is `null`. |
|
|
184
|
+
| `min max` | Follow the field's order: numbers, dates by day or moment, text in the locale's collation. Over no values they are `null`. |
|
|
185
|
+
|
|
186
|
+
`skipEmpty` leaves empty values (`null`, `undefined`, `''`, `NaN`) out of an item; its default is `true`. With `false`, `sum` and `avg` count them as 0, which changes the denominator of `avg`; `min` and `max` have no order for them and leave them out either way. The option works in memory only: a backend computes summaries its own way.
|
|
187
|
+
|
|
188
|
+
In memory, a summary reads its field through the evaluate context's `summaryValue` when the caller provides one, for computed values. `data.summarize(rows, items, context)` computes the same summary values over an array, and `data.SummaryRule` carries one item's rule: `start()` returns an accumulator fed one row at a time, for computing the same summaries over rows a view already holds.
|
|
189
|
+
|
|
190
|
+
The example groups the orders by city, and inside each city by product, with the `sum` of the amounts as the group summary, three top-level groups a page. The list mirrors the shape of `groups`: one line per group with its `field`, `key`, `count` and `summary`, the levels nested. The orders without a city form the group whose key is `null`, on the last page. Under the groups stand the query's own `summary` values, computed over all 240 orders on every page.
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
/** An order of the examples on this page. */
|
|
194
|
+
export interface Order {
|
|
195
|
+
id: number;
|
|
196
|
+
customer: string;
|
|
197
|
+
city: string | null;
|
|
198
|
+
product: string;
|
|
199
|
+
orderedOn: string;
|
|
200
|
+
amount: number;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const CUSTOMERS = ['Elif Demir', 'Can Yılmaz', 'Zeynep Kaya', 'Mert Şahin', 'Ayşe Çelik', 'Deniz Arslan', 'Burak Koç', 'Selin Aydın'];
|
|
204
|
+
const CITIES = ['Ankara', 'Bursa', 'İstanbul', 'İzmir', 'Konya', 'Trabzon'];
|
|
205
|
+
const PRODUCTS = ['Desk', 'Chair', 'Lamp', 'Shelf', 'Monitor', 'Keyboard'];
|
|
206
|
+
|
|
207
|
+
/** `n` orders, the same ones every time; every 19th has no city, so blank values can be tried. */
|
|
208
|
+
export function makeOrders(n = 240): Order[] {
|
|
209
|
+
const day = Date.UTC(2026, 0, 1);
|
|
210
|
+
return Array.from({ length: n }, (_, i) => ({
|
|
211
|
+
id: i + 1,
|
|
212
|
+
customer: CUSTOMERS[(i * 5) % CUSTOMERS.length],
|
|
213
|
+
city: i % 19 === 0 ? null : CITIES[(i * 7) % CITIES.length],
|
|
214
|
+
product: PRODUCTS[Math.floor(i / 6) % PRODUCTS.length],
|
|
215
|
+
orderedOn: new Date(day + ((i * 37) % 300) * 86_400_000).toISOString().slice(0, 10),
|
|
216
|
+
amount: 40 + ((i * 7919) % 90_000) / 100,
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Where the work runs
|
|
222
|
+
|
|
223
|
+
A backend runs the parts of a query its capabilities include, and the adapter runs the rest in memory over the rows the backend returns; [the overview](datalayer.md#capabilities) introduces the split and [the API reference](datalayer-api.md#capabilities) lists every capability. The split keeps results exact: filtering, sorting, grouping or summarizing in memory needs every matching row, so paging and counting move into memory with them; grouping and summaries stay together; and a field selection is applied after the memory work, so it never drops a field the work reads.
|
|
224
|
+
|
|
225
|
+
The same engine is callable directly: `data.queryArray(rows, options, context)` runs a whole `LoadOptions` over an array and returns a `LoadResult`; it is what the `ArrayAdapter` answers with. Without `select`, the rows of the result are the array's own objects. The context is optional; `adapter.evaluateContext` gives an adapter's own, built from its options.
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
const result = data.queryArray(
|
|
229
|
+
orders,
|
|
230
|
+
{
|
|
231
|
+
filter: data.where('city', '=', 'Ankara'),
|
|
232
|
+
group: [{ field: 'product' }],
|
|
233
|
+
groupSummary: [{ type: 'sum', field: 'amount' }],
|
|
234
|
+
count: true,
|
|
235
|
+
},
|
|
236
|
+
{ locale: 'tr', fields: { orderedOn: 'date' } },
|
|
237
|
+
);
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## API reference
|
|
241
|
+
|
|
242
|
+
### LoadOptions
|
|
243
|
+
|
|
244
|
+
| Option | Type | Description |
|
|
245
|
+
| --- | --- | --- |
|
|
246
|
+
| `filter` | `FilterExpression \| null` | The rows the query matches. See [Filters as data](#filters). |
|
|
247
|
+
| `sort` | `SortItem[]` | The order of the rows: `{ field, dir }` items, applied in order. See [Sorting](#sorting). |
|
|
248
|
+
| `skip` | `number` | Rows left out before the page, 0 or more (fractions are floored); with `group`, top-level groups. |
|
|
249
|
+
| `take` | `number` | Rows the page holds; with `group`, top-level groups. |
|
|
250
|
+
| `count` | `boolean` | Also returns the number of matching rows in `total` and, with `group`, of top-level groups in `groupCount`. |
|
|
251
|
+
| `select` | `string[]` | The fields the rows of the result hold; a dotted path reaches a nested field. See [Selecting fields](#paging). |
|
|
252
|
+
| `expand` | `string[]` | Related data to include, OData's `$expand` ([OData](datalayer-odata.md)); a backend without the concept ignores it. |
|
|
253
|
+
| `group` | `GroupItem[]` | Grouping levels; the result holds `groups`, and `rows` in group order. See [Groups](#groups). |
|
|
254
|
+
| `groupsOnly` | `boolean` | With `group`: only the groups with their keys, counts and `groupSummary`, no rows; `rows` is empty. |
|
|
255
|
+
| `groupSummary` | `SummaryItem[]` | Summary values of each group, at every level. |
|
|
256
|
+
| `summary` | `SummaryItem[]` | Summary values of all matching rows, not only the page. See [Summaries](#summaries). |
|
|
257
|
+
| `params` | `Record<string, unknown>` | Passed to the backend as they are. |
|
|
258
|
+
| `signal` | `AbortSignal` | Cancels the load; a cancelled load rejects with `MJD105`. |
|
|
259
|
+
|
|
260
|
+
### LoadResult
|
|
261
|
+
|
|
262
|
+
| Member | Type | Description |
|
|
263
|
+
| --- | --- | --- |
|
|
264
|
+
| `rows` | `T[]` | The rows of the page; with `group`, every row of the page's groups, in group order; empty with `groupsOnly`. |
|
|
265
|
+
| `total` | `number` | With `count`: the number of matching rows, paging aside. |
|
|
266
|
+
| `groups` | `RowGroup<T>[]` | With `group`: the top-level groups of the page. |
|
|
267
|
+
| `groupCount` | `number` | With `group` and `count`: the number of top-level groups. |
|
|
268
|
+
| `summary` | `unknown[]` | With `summary`: its values, in the order of the items. |
|
|
269
|
+
|
|
270
|
+
### Filter types
|
|
271
|
+
|
|
272
|
+
| Member | Description |
|
|
273
|
+
| --- | --- |
|
|
274
|
+
| `FilterExpression` | A `FilterCondition`, or `{ and: FilterExpression[] }`, `{ or: FilterExpression[] }`, `{ not: FilterExpression }`. Plain data, so a filter can be kept, sent and translated into each backend's query language. |
|
|
275
|
+
| `FilterCondition.field` | The field the condition reads; a dotted path reaches a nested value. |
|
|
276
|
+
| `FilterCondition.op` | A `FilterOperator`: one of the [operators](#filters) above. |
|
|
277
|
+
| `FilterCondition.value` | The value compared: `[from, to]` for `between`, an array for `in` and `notin`, none for `isblank` and `isnotblank`. |
|
|
278
|
+
| `FilterCondition.caseSensitive` | Compares text exactly. The default compares without case, in the locale. |
|
|
279
|
+
| `FilterCondition.interval` | Compares the field through an interval, as a pivot level groups it. See [Conditions through an interval](#filters). |
|
|
280
|
+
|
|
281
|
+
### Sort, group and summary items
|
|
282
|
+
|
|
283
|
+
| Type | Meaning |
|
|
284
|
+
| --- | --- |
|
|
285
|
+
| `SortItem` | `{ field, dir }`: one sort level; `dir` is `'asc'` or `'desc'`. A dotted `field` reads a nested value. |
|
|
286
|
+
| `GroupItem` | `{ field, dir? }`: one grouping level; rows with the same value of `field` form a group, ordered by that value. `dir` defaults to `'asc'`. |
|
|
287
|
+
| `SummaryItem` | `{ type, field?, skipEmpty? }`: one summary value. See [Summaries](#summaries). |
|
|
288
|
+
|
|
289
|
+
### RowGroup
|
|
290
|
+
|
|
291
|
+
| Member | Description |
|
|
292
|
+
| --- | --- |
|
|
293
|
+
| `field` | The field of the grouping level. |
|
|
294
|
+
| `key` | The value of `field` in the group, as the first row of the group holds it; `null` for empty values. |
|
|
295
|
+
| `count` | The rows in the group, all levels below included. |
|
|
296
|
+
| `items` | The rows of the group, on the last grouping level; left out above it and with `groupsOnly`. |
|
|
297
|
+
| `groups` | The groups of the level below, above the last level. |
|
|
298
|
+
| `summary` | The values of `groupSummary`, in order. |
|
|
299
|
+
|
|
300
|
+
### EvaluateContext
|
|
301
|
+
|
|
302
|
+
The context the memory engine reads rows with; `createRowFilter`, `sortRows`, `queryArray` and `summarize` all take one. An adapter builds its own from its options (`adapter.evaluateContext`). `groupValue`, `groupCompare` and `summaryValue` have no adapter option: callers of the engine, such as the kit's components, pass them for computed values of their own.
|
|
303
|
+
|
|
304
|
+
| Member | Description |
|
|
305
|
+
| --- | --- |
|
|
306
|
+
| `fields` | The declared field types, as the adapter option of the same name. |
|
|
307
|
+
| `locale` | The locale text is compared in. |
|
|
308
|
+
| `filterValue` | Filtering reads the field with this function instead (a computed value). |
|
|
309
|
+
| `sortValue` | Sorting reads the field with this function instead (a computed value). |
|
|
310
|
+
| `compare` | Sorting compares the field's values with this function instead of the type rules; empty values still go last. |
|
|
311
|
+
| `groupValue` | Grouping reads the field with this function instead (a value of its own to group by), also to order the groups. |
|
|
312
|
+
| `groupCompare` | The groups of a field are ordered with this function instead (of their values); empty values still go last. |
|
|
313
|
+
| `summaryValue` | Summaries read the field with this function instead (a computed value). |
|
|
314
|
+
|
|
315
|
+
## Feedback
|
|
316
|
+
|
|
317
|
+
Loading issues…
|
|
318
|
+
|
|
319
|
+
## Example files
|
|
320
|
+
|
|
321
|
+
`Playground.tsx`
|
|
322
|
+
|
|
323
|
+
```tsx
|
|
324
|
+
import { reactive } from '@motifx/core';
|
|
325
|
+
import { data } from '@motifx-community/data';
|
|
326
|
+
import { DataGrid, DropDown, Pagination, Stack, TextBox, type GridColumn } from '@motifx-community/ui';
|
|
327
|
+
import { makeOrders, type Order } from './orders';
|
|
328
|
+
|
|
329
|
+
const FIELDS = ['customer', 'city', 'product', 'orderedOn', 'amount'];
|
|
330
|
+
const OPS = ['=', '<>', '<', '<=', '>', '>=', 'contains', 'notcontains', 'startswith', 'endswith', 'isblank', 'isnotblank'];
|
|
331
|
+
const PAGE = 8;
|
|
332
|
+
|
|
333
|
+
const columns: GridColumn<Order>[] = [
|
|
334
|
+
{ field: 'id', title: 'No', type: 'number', width: 70, sortable: false },
|
|
335
|
+
{ field: 'customer', title: 'Customer', width: 150, flex: 1, sortable: false },
|
|
336
|
+
{ field: 'city', title: 'City', width: 110, sortable: false },
|
|
337
|
+
{ field: 'product', title: 'Product', width: 110, sortable: false },
|
|
338
|
+
{ field: 'orderedOn', title: 'Ordered on', type: 'date', width: 120, sortable: false },
|
|
339
|
+
{ field: 'amount', title: 'Amount', type: 'number', width: 100, sortable: false },
|
|
340
|
+
];
|
|
341
|
+
|
|
342
|
+
/** One or two conditions, a sort and a page, run over 240 orders in an ArrayAdapter. */
|
|
343
|
+
export default function Playground() {
|
|
344
|
+
const s = reactive({
|
|
345
|
+
field: 'city', op: '=', text: 'Ankara',
|
|
346
|
+
join: 'and', field2: 'amount', op2: '>=', text2: '250',
|
|
347
|
+
sortField: 'amount', sortDir: 'desc' as 'asc' | 'desc',
|
|
348
|
+
page: 1, total: 0, rows: [] as Order[],
|
|
349
|
+
});
|
|
350
|
+
const orders = new data.ArrayAdapter<Order, number>({ data: makeOrders(240), key: 'id', fields: { orderedOn: 'date', amount: 'number' } });
|
|
351
|
+
|
|
352
|
+
// The value of a condition: none for the blank tests, a number for the amount field, otherwise the text.
|
|
353
|
+
const valueOf = (field: string, op: string, text: string): unknown =>
|
|
354
|
+
op === 'isblank' || op === 'isnotblank' ? undefined : field === 'amount' ? (text.trim() === '' ? null : Number(text)) : text;
|
|
355
|
+
const condition = (field: string, op: string, text: string) => data.where(field, op as data.FilterOperator, valueOf(field, op, text));
|
|
356
|
+
const filterOf = (): data.FilterExpression => {
|
|
357
|
+
const first = condition(s.field, s.op, s.text);
|
|
358
|
+
if (s.join === 'none') return first;
|
|
359
|
+
const second = condition(s.field2, s.op2, s.text2);
|
|
360
|
+
return (s.join === 'and' ? data.and(first, second) : data.or(first, second))!;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const lit = (v: unknown) => (typeof v === 'string' ? `'${v}'` : String(v));
|
|
364
|
+
const whereCode = (field: string, op: string, text: string) => {
|
|
365
|
+
const v = valueOf(field, op, text);
|
|
366
|
+
return v === undefined ? `data.where('${field}', '${op}')` : `data.where('${field}', '${op}', ${lit(v)})`;
|
|
367
|
+
};
|
|
368
|
+
const codeText = () => {
|
|
369
|
+
const first = whereCode(s.field, s.op, s.text);
|
|
370
|
+
const filter = s.join === 'none' ? first : `data.${s.join}(\n ${first},\n ${whereCode(s.field2, s.op2, s.text2)},\n )`;
|
|
371
|
+
return `await orders.load({\n filter: ${filter},\n sort: [{ field: '${s.sortField}', dir: '${s.sortDir}' }],\n skip: ${(s.page - 1) * PAGE}, take: ${PAGE}, count: true,\n});`;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
let last = 0;
|
|
375
|
+
const run = async () => {
|
|
376
|
+
const mine = ++last;
|
|
377
|
+
const options: data.LoadOptions = {
|
|
378
|
+
filter: filterOf(),
|
|
379
|
+
sort: [{ field: s.sortField, dir: s.sortDir }],
|
|
380
|
+
skip: (s.page - 1) * PAGE,
|
|
381
|
+
take: PAGE,
|
|
382
|
+
count: true,
|
|
383
|
+
};
|
|
384
|
+
const result = await orders.load(options);
|
|
385
|
+
if (mine !== last) return;
|
|
386
|
+
s.rows = result.rows;
|
|
387
|
+
s.total = result.total ?? 0;
|
|
388
|
+
if (!result.rows.length && s.page > 1) s.page = 1;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
return (
|
|
392
|
+
<div class="dlq-playground" onConfig={(c) => c.bindings.watch(() => void run())}>
|
|
393
|
+
<Stack orientation="horizontal" wrap align="end">
|
|
394
|
+
<DropDown label="Field" items={FIELDS} x-model={() => s.field} />
|
|
395
|
+
<DropDown label="Operator" items={OPS} x-model={() => s.op} />
|
|
396
|
+
<TextBox label="Value" updateOn="input" x-model={() => s.text} enabled={() => s.op !== 'isblank' && s.op !== 'isnotblank'} />
|
|
397
|
+
</Stack>
|
|
398
|
+
<Stack orientation="horizontal" wrap align="end">
|
|
399
|
+
<DropDown label="Join with" items={['none', 'and', 'or']} x-model={() => s.join} />
|
|
400
|
+
<DropDown label="Field" items={FIELDS} x-model={() => s.field2} enabled={() => s.join !== 'none'} />
|
|
401
|
+
<DropDown label="Operator" items={OPS} x-model={() => s.op2} enabled={() => s.join !== 'none'} />
|
|
402
|
+
<TextBox label="Value" updateOn="input" x-model={() => s.text2} enabled={() => s.join !== 'none' && s.op2 !== 'isblank' && s.op2 !== 'isnotblank'} />
|
|
403
|
+
</Stack>
|
|
404
|
+
<Stack orientation="horizontal" wrap align="end">
|
|
405
|
+
<DropDown label="Sort by" items={FIELDS} x-model={() => s.sortField} />
|
|
406
|
+
<DropDown label="Direction" items={['asc', 'desc']} x-model={() => s.sortDir} />
|
|
407
|
+
<output class="dlq-total">{() => `${s.total} matching orders`}</output>
|
|
408
|
+
</Stack>
|
|
409
|
+
<pre class="dlq-code">{() => codeText()}</pre>
|
|
410
|
+
<pre class="dlq-json">{() => JSON.stringify(filterOf(), null, 2)}</pre>
|
|
411
|
+
<DataGrid class="dlq-grid" style="block-size: 19rem" rows={() => s.rows} rowKey="id" columns={columns} label="The page the load returns" locale="en" />
|
|
412
|
+
<Pagination label="Pages of matching orders" total={() => s.total} pageSize={PAGE} x-model={() => s.page} />
|
|
413
|
+
</div>
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
`orders.ts`
|
|
419
|
+
|
|
420
|
+
```tsx
|
|
421
|
+
/** An order of the examples on this page. */
|
|
422
|
+
export interface Order {
|
|
423
|
+
id: number;
|
|
424
|
+
customer: string;
|
|
425
|
+
city: string | null;
|
|
426
|
+
product: string;
|
|
427
|
+
orderedOn: string;
|
|
428
|
+
amount: number;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const CUSTOMERS = ['Elif Demir', 'Can Yılmaz', 'Zeynep Kaya', 'Mert Şahin', 'Ayşe Çelik', 'Deniz Arslan', 'Burak Koç', 'Selin Aydın'];
|
|
432
|
+
const CITIES = ['Ankara', 'Bursa', 'İstanbul', 'İzmir', 'Konya', 'Trabzon'];
|
|
433
|
+
const PRODUCTS = ['Desk', 'Chair', 'Lamp', 'Shelf', 'Monitor', 'Keyboard'];
|
|
434
|
+
|
|
435
|
+
/** `n` orders, the same ones every time; every 19th has no city, so blank values can be tried. */
|
|
436
|
+
export function makeOrders(n = 240): Order[] {
|
|
437
|
+
const day = Date.UTC(2026, 0, 1);
|
|
438
|
+
return Array.from({ length: n }, (_, i) => ({
|
|
439
|
+
id: i + 1,
|
|
440
|
+
customer: CUSTOMERS[(i * 5) % CUSTOMERS.length],
|
|
441
|
+
city: i % 19 === 0 ? null : CITIES[(i * 7) % CITIES.length],
|
|
442
|
+
product: PRODUCTS[Math.floor(i / 6) % PRODUCTS.length],
|
|
443
|
+
orderedOn: new Date(day + ((i * 37) % 300) * 86_400_000).toISOString().slice(0, 10),
|
|
444
|
+
amount: 40 + ((i * 7919) % 90_000) / 100,
|
|
445
|
+
}));
|
|
446
|
+
}
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
`Groups.tsx`
|
|
450
|
+
|
|
451
|
+
```tsx
|
|
452
|
+
import { reactive } from '@motifx/core';
|
|
453
|
+
import { data } from '@motifx-community/data';
|
|
454
|
+
import { CheckBox, Pagination, Stack } from '@motifx-community/ui';
|
|
455
|
+
import { makeOrders, type Order } from './orders';
|
|
456
|
+
|
|
457
|
+
interface Line {
|
|
458
|
+
key: string;
|
|
459
|
+
depth: number;
|
|
460
|
+
text: string;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const GROUPS_A_PAGE = 3;
|
|
464
|
+
|
|
465
|
+
/** The orders grouped by city, and inside each city by product, with group summaries and the query's own summary. */
|
|
466
|
+
export default function Groups() {
|
|
467
|
+
const s = reactive({ second: true, page: 1, lines: [] as Line[], groupCount: 0, rowCount: 0, summary: '' });
|
|
468
|
+
const orders = new data.ArrayAdapter<Order, number>({ data: makeOrders(240), key: 'id', fields: { orderedOn: 'date', amount: 'number' } });
|
|
469
|
+
|
|
470
|
+
// One line per group, nested levels indented: the shape of `groups` as text.
|
|
471
|
+
const lines = (groups: data.RowGroup<Order>[], depth: number, at: string): Line[] =>
|
|
472
|
+
groups.flatMap((g) => {
|
|
473
|
+
const key = `${at}/${String(g.key)}`;
|
|
474
|
+
const sum = (g.summary?.[0] as number) ?? 0;
|
|
475
|
+
const line = { key, depth, text: `${g.field}: ${JSON.stringify(g.key)} · count ${g.count} · summary [${sum.toFixed(2)}]` };
|
|
476
|
+
return [line, ...(g.groups ? lines(g.groups, depth + 1, key) : [])];
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
let last = 0;
|
|
480
|
+
const run = async () => {
|
|
481
|
+
const mine = ++last;
|
|
482
|
+
const result = await orders.load({
|
|
483
|
+
group: s.second ? [{ field: 'city' }, { field: 'product' }] : [{ field: 'city' }],
|
|
484
|
+
groupSummary: [{ type: 'sum', field: 'amount' }],
|
|
485
|
+
summary: [{ type: 'count' }, { type: 'sum', field: 'amount' }, { type: 'avg', field: 'amount' }],
|
|
486
|
+
skip: (s.page - 1) * GROUPS_A_PAGE,
|
|
487
|
+
take: GROUPS_A_PAGE,
|
|
488
|
+
count: true,
|
|
489
|
+
});
|
|
490
|
+
if (mine !== last) return;
|
|
491
|
+
s.lines = lines(result.groups ?? [], 0, '');
|
|
492
|
+
s.groupCount = result.groupCount ?? 0;
|
|
493
|
+
s.rowCount = result.rows.length;
|
|
494
|
+
const [count, sum, avg] = result.summary as number[];
|
|
495
|
+
s.summary = `summary: [${count}, ${sum.toFixed(2)}, ${avg.toFixed(2)}] (count, sum and avg of the amounts of all 240 orders)`;
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
return (
|
|
499
|
+
<div class="dlq-groups" onConfig={(c) => c.bindings.watch(() => void run())}>
|
|
500
|
+
<Stack orientation="horizontal" wrap align="center">
|
|
501
|
+
<CheckBox label="Group by product inside each city" x-model={() => s.second} />
|
|
502
|
+
<output class="dlq-groups-rows">{() => `rows holds the ${s.rowCount} rows of these groups, in group order`}</output>
|
|
503
|
+
</Stack>
|
|
504
|
+
<ul class="dlq-groups-list" aria-label="The groups of the result">
|
|
505
|
+
{s.lines.map((l) => (
|
|
506
|
+
<li key={l.key} style={`padding-inline-start: ${l.depth * 1.5}rem`}>
|
|
507
|
+
{l.text}
|
|
508
|
+
</li>
|
|
509
|
+
))}
|
|
510
|
+
</ul>
|
|
511
|
+
<output class="dlq-groups-summary">{() => s.summary}</output>
|
|
512
|
+
<Pagination label="Top-level groups" total={() => s.groupCount} pageSize={GROUPS_A_PAGE} x-model={() => s.page} />
|
|
513
|
+
</div>
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
```
|