@datagrok/grokky 1.0.4 → 1.1.0

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.
Files changed (203) hide show
  1. package/.claude/skills/deploy-grokky/SKILL.md +193 -0
  2. package/.grokignore +2 -0
  3. package/.turbo/turbo-build.log +24 -0
  4. package/.vscode/settings.json +16 -0
  5. package/CHANGELOG.md +151 -8
  6. package/CLAUDE.md +284 -0
  7. package/CREDITS.md +173 -0
  8. package/LICENSE.md +16 -0
  9. package/README.md +24 -0
  10. package/bdd/bdd.config.json +1 -0
  11. package/bdd/bindings/elements.ts +9 -0
  12. package/bdd/bindings/steps.ts +787 -0
  13. package/bdd/features/ai-panel/platform-work.feature +63 -0
  14. package/bdd/features/ai-panel/session.feature +69 -0
  15. package/bdd/features/ai-panel/table-work.feature +99 -0
  16. package/bdd/generated/ai-panel/platform-work.test.ts +103 -0
  17. package/bdd/generated/ai-panel/session.test.ts +100 -0
  18. package/bdd/generated/ai-panel/table-work.test.ts +150 -0
  19. package/bdd/package.json +1 -0
  20. package/bdd/tsconfig.json +13 -0
  21. package/css/ai.css +637 -49
  22. package/dist/package-test.js +4 -1707
  23. package/dist/package-test.js.map +1 -1
  24. package/dist/package.js +742 -92317
  25. package/dist/package.js.map +1 -1
  26. package/dockerfiles/claude-runtime/.dockerignore +1 -0
  27. package/{.eslintrc.json → dockerfiles/claude-runtime/.eslintrc.json} +7 -16
  28. package/dockerfiles/claude-runtime/Dockerfile +73 -13
  29. package/dockerfiles/claude-runtime/agent/grokky_agent/__init__.py +0 -0
  30. package/dockerfiles/claude-runtime/agent/grokky_agent/__main__.py +80 -0
  31. package/dockerfiles/claude-runtime/agent/grokky_agent/browser_tools.py +180 -0
  32. package/dockerfiles/claude-runtime/agent/grokky_agent/config.py +26 -0
  33. package/dockerfiles/claude-runtime/agent/grokky_agent/formats.py +155 -0
  34. package/dockerfiles/claude-runtime/agent/grokky_agent/guard.py +87 -0
  35. package/dockerfiles/claude-runtime/agent/grokky_agent/hermes.py +212 -0
  36. package/dockerfiles/claude-runtime/agent/grokky_agent/hermes.yaml +45 -0
  37. package/dockerfiles/claude-runtime/agent/grokky_agent/hermes_plugin/__init__.py +8 -0
  38. package/dockerfiles/claude-runtime/agent/grokky_agent/hermes_plugin/plugin.yaml +3 -0
  39. package/dockerfiles/claude-runtime/agent/grokky_agent/protocol.py +174 -0
  40. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/__init__.py +21 -0
  41. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/anthropic.py +21 -0
  42. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/azure.py +46 -0
  43. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/base.py +127 -0
  44. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/bedrock.py +46 -0
  45. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/custom.py +40 -0
  46. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/databricks.py +54 -0
  47. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/openai_platform.py +41 -0
  48. package/dockerfiles/claude-runtime/agent/grokky_agent/providers/openrouter.py +46 -0
  49. package/dockerfiles/claude-runtime/agent/grokky_agent/session.py +471 -0
  50. package/dockerfiles/claude-runtime/agent/grokky_agent/skills.py +44 -0
  51. package/dockerfiles/claude-runtime/agent/grokky_agent/structured.py +40 -0
  52. package/dockerfiles/claude-runtime/container.json +2 -2
  53. package/dockerfiles/claude-runtime/entrypoint.sh +20 -0
  54. package/dockerfiles/claude-runtime/package-lock.json +1721 -306
  55. package/dockerfiles/claude-runtime/package.json +20 -5
  56. package/dockerfiles/claude-runtime/plugin/.claude-plugin/plugin.json +5 -0
  57. package/dockerfiles/claude-runtime/plugin/skills/datagrok-calc-column/SKILL.md +92 -0
  58. package/dockerfiles/claude-runtime/plugin/skills/datagrok-chem-data/SKILL.md +250 -0
  59. package/dockerfiles/claude-runtime/plugin/skills/datagrok-chem-toolkit/SKILL.md +395 -0
  60. package/dockerfiles/claude-runtime/plugin/skills/datagrok-df-and-columns/SKILL.md +454 -0
  61. package/dockerfiles/claude-runtime/plugin/skills/datagrok-entities/SKILL.md +38 -0
  62. package/dockerfiles/claude-runtime/plugin/skills/datagrok-exec/SKILL.md +209 -0
  63. package/dockerfiles/claude-runtime/plugin/skills/datagrok-filtering/SKILL.md +185 -0
  64. package/dockerfiles/claude-runtime/plugin/skills/datagrok-grid-customization/SKILL.md +270 -0
  65. package/dockerfiles/claude-runtime/plugin/skills/datagrok-projects/SKILL.md +100 -0
  66. package/dockerfiles/claude-runtime/plugin/skills/datagrok-selection/SKILL.md +344 -0
  67. package/dockerfiles/claude-runtime/plugin/skills/datagrok-undo/SKILL.md +78 -0
  68. package/dockerfiles/claude-runtime/plugin/skills/datagrok-viewers/SKILL.md +303 -0
  69. package/dockerfiles/claude-runtime/pyproject.toml +18 -0
  70. package/dockerfiles/claude-runtime/src/agent/pool.ts +411 -0
  71. package/dockerfiles/claude-runtime/src/agent/turn.ts +153 -0
  72. package/dockerfiles/claude-runtime/src/constants.ts +20 -0
  73. package/dockerfiles/claude-runtime/src/credentials.ts +45 -0
  74. package/dockerfiles/claude-runtime/src/grounding.ts +104 -0
  75. package/dockerfiles/claude-runtime/src/help-index.ts +118 -0
  76. package/dockerfiles/claude-runtime/src/privileges.ts +8 -0
  77. package/dockerfiles/claude-runtime/src/prompts.ts +211 -0
  78. package/dockerfiles/claude-runtime/src/server.ts +134 -234
  79. package/dockerfiles/claude-runtime/src/session.ts +328 -0
  80. package/dockerfiles/claude-runtime/src/shared-api-client.ts +112 -0
  81. package/dockerfiles/claude-runtime/src/stream-filter.ts +80 -0
  82. package/dockerfiles/claude-runtime/src/sync/home-files.ts +80 -0
  83. package/dockerfiles/claude-runtime/src/sync/orchestrator.ts +214 -0
  84. package/dockerfiles/claude-runtime/src/sync/packages.ts +145 -0
  85. package/dockerfiles/claude-runtime/src/sync/shared-connections.ts +87 -0
  86. package/dockerfiles/claude-runtime/src/sync/workspace.ts +68 -0
  87. package/dockerfiles/claude-runtime/src/tasks.ts +124 -0
  88. package/dockerfiles/claude-runtime/src/tool-summary.ts +66 -0
  89. package/dockerfiles/claude-runtime/src/types.ts +142 -23
  90. package/dockerfiles/claude-runtime/src/user/installed-packages.ts +17 -0
  91. package/dockerfiles/claude-runtime/src/user/staged-workspace.ts +80 -0
  92. package/dockerfiles/claude-runtime/src/user/user-dir.ts +108 -0
  93. package/dockerfiles/claude-runtime/src/verify.ts +136 -0
  94. package/dockerfiles/claude-runtime/src/watchdog.ts +115 -0
  95. package/dockerfiles/claude-runtime/test/credentials.test.js +43 -0
  96. package/dockerfiles/claude-runtime/test/grounding.test.js +191 -0
  97. package/dockerfiles/claude-runtime/test/help-index.test.js +115 -0
  98. package/dockerfiles/claude-runtime/test/plugin-skills.test.js +57 -0
  99. package/dockerfiles/claude-runtime/test/prompts.test.js +62 -0
  100. package/dockerfiles/claude-runtime/test/reaper.test.js +60 -0
  101. package/dockerfiles/claude-runtime/test/stream-filter.test.js +132 -0
  102. package/dockerfiles/claude-runtime/test/tasks.test.js +74 -0
  103. package/dockerfiles/claude-runtime/test/user-dir.test.js +71 -0
  104. package/dockerfiles/claude-runtime/test/verify.test.js +187 -0
  105. package/dockerfiles/claude-runtime/test/watchdog.test.js +43 -0
  106. package/dockerfiles/mcp-server/.eslintrc.json +39 -0
  107. package/dockerfiles/mcp-server/Dockerfile +10 -2
  108. package/dockerfiles/mcp-server/package-lock.json +1743 -98
  109. package/dockerfiles/mcp-server/package.json +27 -5
  110. package/dockerfiles/mcp-server/src/api-client.ts +123 -66
  111. package/dockerfiles/mcp-server/src/format.ts +51 -0
  112. package/dockerfiles/mcp-server/src/index.ts +44 -113
  113. package/dockerfiles/mcp-server/src/ops.ts +325 -0
  114. package/dockerfiles/mcp-server/src/shared-api-client.ts +81 -0
  115. package/dockerfiles/mcp-server/test/format.test.js +62 -0
  116. package/dockerfiles/mcp-server/test/ops.test.js +84 -0
  117. package/dockerfiles/mcp-server/test/shared-api-client.test.js +35 -0
  118. package/dockerfiles/queue/Dockerfile +2 -0
  119. package/dockerfiles/queue/container.json +7 -0
  120. package/docs/AUDIT-2026-08-03.md +1064 -0
  121. package/docs/BENCHMARK.md +292 -0
  122. package/docs/CLAUDE_CODE_FLOW.md +746 -0
  123. package/docs/EXAMPLES.md +82 -0
  124. package/docs/FEATURES.md +71 -0
  125. package/docs/IMPLEMENTATION.md +128 -0
  126. package/docs/LATENCY.md +170 -0
  127. package/docs/VISION.md +36 -0
  128. package/files/benchmark/suite.yaml +404 -0
  129. package/files/scripts/process-cro-results.md +14 -0
  130. package/files/suggestions.yaml +344 -0
  131. package/package.json +39 -97
  132. package/src/ai/ai-window.ts +157 -0
  133. package/src/ai/benchmark/benchmark.ts +737 -0
  134. package/src/ai/db-view-functions.ts +56 -0
  135. package/src/ai/engine.ts +98 -0
  136. package/src/ai/gemma-engine.ts +81 -0
  137. package/src/ai/panel.ts +1385 -0
  138. package/src/ai/prompt-suggestions.ts +209 -0
  139. package/src/ai/search/combined-search.ts +244 -0
  140. package/src/{llm-utils → ai/search}/query-matching.ts +46 -167
  141. package/src/{llm-utils → ai}/storage.ts +0 -1
  142. package/src/ai/table-tools.ts +145 -0
  143. package/src/ai/ui.ts +720 -0
  144. package/src/ai/usage-limiter.ts +105 -0
  145. package/src/ai/view-tools.ts +352 -0
  146. package/src/claude/ai-feature.ts +16 -0
  147. package/src/claude/exec-blocks.ts +176 -0
  148. package/src/claude/queue-task.ts +84 -0
  149. package/src/claude/runtime-client.ts +310 -0
  150. package/src/claude/turn-log.ts +114 -0
  151. package/src/claude/undoable.ts +105 -0
  152. package/src/{llm-utils → db}/db-index-tools.ts +24 -32
  153. package/src/db/sql-tools.ts +336 -0
  154. package/src/depr/LLM-client.ts +251 -0
  155. package/src/depr/ai-panel.ts +174 -0
  156. package/src/depr/chatgpt-assistant.ts +257 -0
  157. package/src/depr/creds.ts +30 -0
  158. package/src/depr/deepwikiclient.ts +118 -0
  159. package/src/depr/indexes/dg-repository-index.ts +266 -0
  160. package/src/depr/interfaces.ts +170 -0
  161. package/src/depr/is-help-request.ts +39 -0
  162. package/src/depr/prompt-engine.ts +52 -0
  163. package/src/depr/rendering-tools.ts +103 -0
  164. package/src/depr/script-tools.ts +785 -0
  165. package/src/depr/tableview-tools.ts +746 -0
  166. package/src/depr/viewers-ai.ts +67 -0
  167. package/src/package-api.ts +87 -28
  168. package/src/package-test.ts +1 -0
  169. package/src/package.g.ts +98 -48
  170. package/src/package.ts +211 -157
  171. package/src/polyfills.ts +12 -0
  172. package/src/utils.ts +128 -0
  173. package/tsconfig.json +8 -70
  174. package/webpack.config.js +3 -49
  175. package/.eslintignore +0 -2
  176. package/src/ai-panel.ts +0 -174
  177. package/src/claude-code/claude-panel.ts +0 -34
  178. package/src/claude-code/claude-runtime-client.ts +0 -148
  179. package/src/llm-utils/LLM-client.ts +0 -251
  180. package/src/llm-utils/combined-search.ts +0 -162
  181. package/src/llm-utils/creds.ts +0 -30
  182. package/src/llm-utils/deepwikiclient.ts +0 -118
  183. package/src/llm-utils/indexes/dg-repository-index.ts +0 -266
  184. package/src/llm-utils/panel.ts +0 -866
  185. package/src/llm-utils/script-tools.ts +0 -784
  186. package/src/llm-utils/sql-tools.ts +0 -840
  187. package/src/llm-utils/tableview-tools.ts +0 -704
  188. package/src/llm-utils/ui.ts +0 -315
  189. package/src/prompt-engine/chatgpt-assistant.ts +0 -257
  190. package/src/prompt-engine/interfaces.ts +0 -170
  191. package/src/prompt-engine/prompt-engine.ts +0 -52
  192. package/src/prompt-engine/rendering-tools.ts +0 -103
  193. package/src/prompts/is-help-request.ts +0 -26
  194. package/src/viewers-ai.ts +0 -67
  195. /package/src/{llm-utils → db}/indexes/biologics-index.ts +0 -0
  196. /package/src/{llm-utils → db}/indexes/chembl-index.ts +0 -0
  197. /package/src/{llm-utils → db}/query-meta-utils.ts +0 -0
  198. /package/src/{llm-utils/depr → depr}/AI-API-providers/openai-chat-completions-provider.ts +0 -0
  199. /package/src/{llm-utils/depr → depr}/AI-API-providers/openai-responses-provider.ts +0 -0
  200. /package/src/{llm-utils/depr → depr}/AI-API-providers/types.ts +0 -0
  201. /package/src/{llm-utils/depr → depr}/depr.ts +0 -0
  202. /package/src/{llm-utils/depr → depr}/embeddings.ts +0 -0
  203. /package/src/{llm-utils/depr → depr}/sql-utils.ts +0 -0
@@ -0,0 +1,209 @@
1
+ ---
2
+ name: datagrok-exec
3
+ description: Use whenever you need the Datagrok browser to actually execute JavaScript — adding viewers, filtering, modifying the view, or returning a result widget to the chat. Open this skill before calling the datagrok_exec tool.
4
+ ---
5
+
6
+ # datagrok-exec
7
+
8
+ The ONLY way code runs in the Datagrok browser is via the **`datagrok_exec` tool**.
9
+ Regular markdown code blocks do NOT execute.
10
+
11
+ Call `datagrok_exec` to *perform* an action the user asked for (add a viewer, filter,
12
+ open a file, run a function). For informational questions — "how do I…", "what
13
+ is…", "explain…", "can you…" — do not call `datagrok_exec`; find the page via
14
+ `workspace/help/INDEX.md`, read it, use it to find needed material, then answer in plain text.
15
+
16
+ ## Globals available inside the code
17
+
18
+ | Variable | Type | Available |
19
+ |----------|-----------------|---------------------------------------------------|
20
+ | `grok` | module | Always |
21
+ | `ui` | module | Always |
22
+ | `DG` | module | Always |
23
+ | `view` | `DG.ViewBase` | Always — check `view.type` for specific view type |
24
+ | `t` | `DG.DataFrame` | Only when `view.type === 'TableView'` |
25
+ | `undoable` | object | Always — changes Ctrl+Z takes back, see `datagrok-undo` |
26
+
27
+ The code runs in an async IIFE, so `await` works directly.
28
+
29
+ A number computed from a column must skip its missing values: take it from `col.stats.{avg,med,min,max,sum,stdev}`,
30
+ which do, not from `col.getRawData()`, where a missing value is a placeholder number; in a loop, skip rows where
31
+ `col.isNone(i)`.
32
+
33
+ ## Tool result
34
+
35
+ The tool returns `{success, returnValue?, verified?, error?}`.
36
+
37
+ **`success` only means the JS did not throw — NOT that the intended effect happened.** A typo'd
38
+ viewer name, a no-op, or an action that ran twice all return `success: true`. `returnValue` is
39
+ whatever object *your own code* chose to `return`; it populates the chat confirmation shown to the
40
+ user, but it is **not proof** — it is self-reported by the same code that took the action. Make your
41
+ code `return` a plain confirmation object so the user sees accurate details:
42
+
43
+ | Action | Return |
44
+ |---------------------|-------------------------------------|
45
+ | open / load table | `{name, rowCount}` |
46
+ | add viewer | `{type}` |
47
+ | filter | `{filteredRowCount, totalRowCount}` |
48
+ | upload DataFrame | `{tableInfoId}` |
49
+ | save layout | `{layoutId}` |
50
+ | open app / view | `{viewName, viewType}` |
51
+ | color / sort / pin | `{column}` |
52
+
53
+ **Error**: `{success: false, error: "..."}` — report verbatim, do not silently retry.
54
+
55
+ **Never pre-announce** success before calling the tool.
56
+
57
+ ## Verifying actions — required with every action
58
+
59
+ Proof does not come from your own action code — it comes from **re-reading live state in a fresh
60
+ scope**. For any state-changing `datagrok_exec`, pass the **`verify`** parameter with the call:
61
+ `{assertion, description}`. The browser runs your action code, then immediately runs the assertion
62
+ in a fresh scope (globals `grok`, `ui`, `DG`, `view`, `t`) that **cannot see your action's
63
+ variables**, and returns its result as `verified: {passed, observed?}` — one round-trip, no
64
+ separate verify call needed.
65
+
66
+ The assertion is yours to design for whatever you changed: re-read that thing and `return` the
67
+ values you read (truthy = verified), e.g. `return {type: col.meta.colors.getType(), hidden: !gc.visible}`.
68
+ A bare `true` is rejected: a comparison can be true for the wrong reason, and the values show what is there.
69
+ `verified.passed: true` → report the observed value, not the value you intended.
70
+ `verified.passed: false` (or missing) → the action is NOT confirmed — but do **not** assume it
71
+ failed: a faulty assertion (wrong property, wrong count, missing `return`) reads exactly the same.
72
+ **Never re-run state-changing action code on a failed verify.** First re-read the affected state
73
+ with a read-only check (a corrected `datagrok_verify` assertion); only if that shows the change is
74
+ genuinely absent, fix and re-run the action — re-running one that already worked creates duplicate
75
+ viewers/columns/rows. The standalone **`datagrok_verify`** tool exists for that fix-loop and for
76
+ MCP calls that changed platform state (it takes the same `{assertion, description}`). The runtime
77
+ blocks the turn from ending until a verification passes (bounded retries — if they run out, the
78
+ response is shown to the user flagged as **unverified**, so never present unverified work as done).
79
+
80
+ Re-reading what an MCP call saved on the server — use these calls as written, without looking them up:
81
+
82
+ | Saved | Assertion |
83
+ |---|---|
84
+ | file | `return await grok.dapi.files.readAsText('Conn:path/file.txt')` (connector-qualified path, e.g. `System:DemoFiles/...`; the user's home connection is `(await grok.dapi.connections.filter('name = "Home"').first()).nqName`) |
85
+ | script | `const s = await grok.dapi.scripts.filter('name = "X"').first(); return s && s.script` |
86
+ | query | `const q = await grok.dapi.queries.filter('name = "X"').first(); return q && q.query` |
87
+ | project | `return await grok.dapi.projects.filter('name = "X"').first()` |
88
+ | space | `const s = (await grok.dapi.spaces.list()).find((x) => x.friendlyName === 'X'); return s && (await grok.dapi.spaces.id(s.id).children.list()).map((c) => c.friendlyName)` |
89
+ | deleted entity | the same lookup, `return` that it is `null` / absent |
90
+
91
+ ## Undo
92
+
93
+ A change to an open table or its view (columns, rows, values, column metadata, viewers) must be undoable with
94
+ Ctrl+Z: make it with the `table_*` tools, or in a script through the `undoable` global. `datagrok-undo` has both
95
+ and the limits of undo; open it before the first such change.
96
+ Do not mention undo in a reply unless the user asks about it.
97
+
98
+ ## Returning a result to the chat
99
+
100
+ Only return an `HTMLElement` when the **explicit user goal** is to see output in the chat
101
+ ("show me the molecule", "display the table", "draw a plot"). Never return HTMLElements for
102
+ intermediate results, confirmation data, or actions where the platform UI is the destination.
103
+ An HTMLElement return replaces the confirmation object — no `returnValue` is sent.
104
+
105
+ Raw scalars, strings, or `DG.DataFrame` will NOT render; convert via the table below:
106
+
107
+ | Result type | How to render |
108
+ |-----------------------------------|------------------------------------------------|
109
+ | scalar | `ui.divText(String(value))` |
110
+ | key-value pairs | `ui.tableFromMap({key: value})` |
111
+ | list of items | `ui.divV(items.map((x) => ui.divText(x)))` |
112
+ | `DG.DataFrame` | `DG.Viewer.grid(df).root` |
113
+ | `DG.Viewer` / `DG.Widget` | `obj.root` |
114
+ | `DG.ViewBase` (incl. apps) | open via `grok.shell.addView(v)` — do NOT return |
115
+ | molecule (SMILES / molblock) | `grok.chem.drawMolecule(smiles, 300, 200)` |
116
+ | macromolecule (HELM) | see [HELM output](#helm-output) below |
117
+ | graphics | see [Graphics output](#graphics-output) below |
118
+
119
+ ## Native top-menu commands
120
+
121
+ If an operation already exists as a top-menu command (aggregate, join, cluster,
122
+ add column, …), invoke it instead of building a custom `ui.dialog`. Walk the menu
123
+ with `find()` (chain through `|` groups), matching leaf text exactly:
124
+
125
+ ```js
126
+ grok.shell.topMenu.find('Data').find('Aggregate Rows...').click();
127
+ grok.shell.topMenu.find('Edit').find('Go To').find('Row...').click();
128
+ ```
129
+
130
+ | Menu | Commands |
131
+ |----------|--------------------------------------------------------------------------------------------------------------------------|
132
+ | `Edit` | `Undo`, `Redo`, `Add New Column...`, `Add Rows...`, `Column Properties...`, `Find and Replace...`, `Go To \| Row...`, `Go To \| Next Selected`, `Go To \| Prev Selected`, `Remove \| Selected Rows`, `Remove \| Selected Columns`, `Remove \| Selected Rows or Columns` |
133
+ | `View` | `Columns`, `Console`, `Context Panel`, `Schema`, `Tables`, `Variables`, `Toolbox`, `Windows`, `Home`, `Reset Filter`, `Edit Tooltip...`, `Embed...`, `Full Screen`, `Presentation Mode`, `Layout \| Save to Gallery`, `Layout \| Open Gallery`, `Layout \| Clone View`, `Layout \| Download`, `Layout \| Clear` |
134
+ | `Select` | `All`, `None`, `Invert`, `All Columns`, `Duplicates...`, `Missing Values...`, `Random Rows...`, `Extract Selected Rows`, `Filter to Column...`, `Selection to Column...`, `Selection to Filter` |
135
+ | `Data` | `Aggregate Rows...` (also pivot), `Join Tables...`, `Link Tables...`, `Compare Tables...`, `Compare Columns...`, `Append Tables...`, `Unpivot...`, `Split Column...`, `Split Column by RegExp...`, `Categorize...`, `Anonymize...`, `Batch Edit...` |
136
+ | `ML` | `Analyze \| PCA...`, `Analyze \| PLS...`, `Analyze \| ANOVA...`, `Analyze \| Multivariate Analysis...`, `Cluster \| DBSCAN...`, `Cluster \| MCL...`, `Models \| Train Model...`, `Models \| Apply Model...`, `Notebooks \| New Notebook...`, `Reduce Dimensionality...`, `Impute Missing Values...`, `Pareto Front...` |
137
+
138
+ ## Per-area skills
139
+
140
+ For task-specific API surface, open the matching skill before writing code:
141
+
142
+ | User intent | Skill |
143
+ |------------------------------------------------|--------------------------------|
144
+ | Find / describe / add / remove / rename columns; set semType/units/format/friendly name; color coding | `datagrok-df-and-columns` |
145
+ | Calculated (formula-driven) columns | `datagrok-calc-column` |
146
+ | Filter rows (range, categorical, contains, substructure, predicate) | `datagrok-filtering` |
147
+ | Select rows; current row; selection ↔ filter | `datagrok-selection` |
148
+ | Add / configure / find / close viewers | `datagrok-viewers` |
149
+ | Make a change undoable with Ctrl+Z; "undo that" | `datagrok-undo` |
150
+ | Grid sort, visibility, widths, pins, freeze; grid-only cell tint | `datagrok-grid-customization` |
151
+ | Cheminformatics: SMILES/MolBlock/InChI/canonicalize | `datagrok-chem-data` / `datagrok-chem-toolkit` |
152
+
153
+ ## Multiple tool calls in one response
154
+
155
+ Each `datagrok_exec` call runs in its own scope (a fresh `new Function(...)` IIFE).
156
+ Calls execute sequentially, but JS variables declared in one call are NOT visible in the next.
157
+
158
+ Persists across calls:
159
+ - The `view` reference and the `t` DataFrame reference (column additions,
160
+ filter changes, and other mutations are visible to later calls)
161
+ - Anything pushed into the platform: viewers added, dialogs opened, columns
162
+ appended, server-side state
163
+
164
+ Does NOT persist: `const`/`let`/`var` bindings, helper functions, cached values.
165
+ A second call must re-derive from `t`.
166
+
167
+ Before consuming a query/function result, check the wrapper's return type in the apiRef:
168
+
169
+ ```js
170
+ // CORRECT — wrapper returns Promise<string>
171
+ const helm = await grok.data.query('Biologics:GetBiologicsPeptideHelmByIdentifier',
172
+ { peptideIdentifier: 'GROKPEP-000002' });
173
+
174
+ // WRONG — assuming a DataFrame because most queries return one
175
+ const df = await grok.data.query('Biologics:GetBiologicsPeptideHelmByIdentifier', {...});
176
+ const helm = df.columns.byIndex(0).get(0);
177
+ ```
178
+
179
+ ## Launching apps & views
180
+
181
+ Datagrok **apps** are functions with `meta.role: app`. Calling one via
182
+ `grok.functions.call('Pkg:appName')` may return a `DG.ViewBase` (or nothing if
183
+ the app opens its own view). A returned view is NOT yet attached to the
184
+ workspace — hand it to `grok.shell.addView()`. Do NOT `return` the view from
185
+ the code; open it.
186
+
187
+ ```js
188
+ const result = await grok.functions.call('Pkg:appName');
189
+ if (result instanceof DG.ViewBase)
190
+ grok.shell.addView(result);
191
+ ```
192
+
193
+ ## HELM output
194
+
195
+ ```js
196
+ const helmInput = await ui.input.helmAsync('', { editable: false });
197
+ helmInput.stringValue = helmString;
198
+ return helmInput.root;
199
+ ```
200
+
201
+ ## Graphics output
202
+
203
+ Returned graphics elements may render blank without intrinsic dimensions.
204
+ Extract Base64-encoded image data and wrap with explicit width and height:
205
+
206
+ ```js
207
+ const b64 = await grok.functions.call('Chem:ChemistryGasteigerPartialCharges', {mol: 'CCC', contours: 10});
208
+ return ui.image('data:image/png;base64,' + b64, 300, 200);
209
+ ```
@@ -0,0 +1,185 @@
1
+ ---
2
+ name: datagrok-filtering
3
+ description: Filter rows of a Datagrok DataFrame via the datagrok_exec tool through the Filters panel — by range, equals/contains/in-set, multi-value, boolean, free-text row expressions, or substructure (SMILES / SMARTS / molblock). Also covers clearing, inverting, the show-only-filtered vs destructive-drop split, and the filter event lifecycle (onRowsFiltering / onFilterChanged / onRowsFiltered). Use whenever the user says "filter", "show only", "hide rows where", "narrow to subset", "find rows that", "contains", "substructure search", "categorical filter", "range filter", "invert", "clear the filter", "clear filters", "drop rows", or asks for the filtered subset as a new table. Does NOT cover selection (separate skill) or generic DataFrame cloning (datagrok-df-and-columns).
4
+ ---
5
+
6
+ # datagrok-filtering
7
+
8
+ Row-shape filtering on `DG.DataFrame` through the **Filters panel**
9
+ (`view.getFiltersGroup(...)` / `view.filters(...)`). Selection lives in
10
+ `datagrok-selection`; generic dataFrame and column inspection in `datagrok-df-and-columns`.
11
+
12
+ Globals inside every `datagrok_exec` call: `grok`, `ui`, `DG`, `view`,
13
+ `t` (the current `DG.DataFrame`, when the view is a `TableView`).
14
+
15
+ ## Always filter through the Filters panel
16
+
17
+ Every user filter goes through the UI FilterGroup
18
+ (`view.getFiltersGroup(...).updateOrAdd(...)`), so the filter shows up in the
19
+ Filters panel where the user can see, adjust, and remove it. This covers every
20
+ condition — range, categorical / equals / in-set, multi-value, boolean,
21
+ substructure, and free-text row expressions (`age > 30`, `sex = "M"`) via the
22
+ FREE_TEXT filter. For several conditions at once, stack one widget per column.
23
+
24
+ **Never write `t.filter` directly** (`t.filter.init`, hand-built BitSet masks) to
25
+ satisfy a filter request — it bypasses the panel, leaves no visible chip, and is
26
+ overwritten the moment any UI filter re-runs. The panel is always enough.
27
+
28
+ ## Quick reference
29
+
30
+ | Intent | Code |
31
+ |-------------------------------------------------------|-------------------------------------------------------------------------------------|
32
+ | Several filters at once (Filters panel) | `view.filters({filters: [{type: DG.FILTER_TYPE.HISTOGRAM, column, min, max}, ...]})` |
33
+ | Single widget — add or update (Filters panel) | `view.getFiltersGroup({createDefaultFilters:true}).updateOrAdd(state)` — state shapes below |
34
+ | Clear all filters | `view.getFiltersGroup(...).setActive(false)` (or `t.filter.setAll(true)`) |
35
+ | Invert | `t.filter.invert()` |
36
+ | New table of the currently-visible rows | `t.clone(t.filter)` |
37
+ | Remove rows (undoable, see `datagrok-undo`) | tool `table_remove_rows`, `where`: `pred(i)` |
38
+
39
+ ## Reading filter state
40
+
41
+ | Need | Use |
42
+ |---------------------------------------|----------------------------------------------|
43
+ | rows currently passing | `t.filter.trueCount` |
44
+ | rows currently hidden | `t.filter.falseCount` |
45
+ | total rows | `t.filter.length` (same as `t.rowCount`) |
46
+ | indices of passing rows | `t.filter.getSelectedIndexes()` (`Int32Array`)|
47
+ | is row `i` passing? | `t.filter.get(i)` |
48
+ | any rows passing / hidden? | `t.filter.anyTrue` / `t.filter.anyFalse` |
49
+
50
+ ```js
51
+ return {visible: t.filter.trueCount, hidden: t.filter.falseCount, total: t.rowCount};
52
+ ```
53
+
54
+ ## Filtering by column value (UI FilterGroup)
55
+
56
+ Add several filters at once with `view.filters(...)`:
57
+
58
+ ```js
59
+ view.filters({filters: [
60
+ {type: DG.FILTER_TYPE.HISTOGRAM, column: 'height', min: 120, max: 150},
61
+ {type: DG.FILTER_TYPE.FREE_TEXT},
62
+ {type: DG.FILTER_TYPE.MULTI_VALUE, column: 'sex', mode: 'OR', include: ['F'], exclude: []},
63
+ {type: DG.FILTER_TYPE.CATEGORICAL, column: 'disease'},
64
+ ]});
65
+ ```
66
+
67
+ For a single filter,
68
+ `view.getFiltersGroup({createDefaultFilters: true}).updateOrAdd(state)`
69
+ adds or updates one widget.
70
+ Provide **every** field a state requires — a partial state renders the widget
71
+ but silently does not filter.
72
+
73
+ State shapes:
74
+
75
+ | State | Behavior |
76
+ |---------------------------------------------------------------------------------------------------------------|--------------------------------------|
77
+ | `{type: DG.FILTER_TYPE.HISTOGRAM, column: 'height', min: 120, max: 150}` | numeric range; **both `min` and `max` are required** — a min-only (or max-only) state does NOT filter. For an open-ended condition, fill the free bound from the column's extent, e.g. `"> X"` → `min: X, max: t.col(name).stats.max` |
78
+ | `{type: DG.FILTER_TYPE.CATEGORICAL, column: 'race', selected: ['Asian', 'Black']}` | in-set; single element = equals; omit `selected` → widget with no constraint |
79
+ | `{type: DG.FILTER_TYPE.MULTI_VALUE, column: 'sex', mode: 'AND'\|'OR', include: ['F'], exclude: []}` | cells holding several values (column's separator tag, default newline); `include`/`exclude` BOTH required (empty array ok, null not); a value in neither list is unconstrained; a `selected` key (seen in older samples) is ignored |
80
+ | `{type: DG.FILTER_TYPE.BOOL_COLUMNS, 'columnless-filter-identifier': 'control', mode: 'AND', true: [true], false: [false]}` | one widget over N bool columns (order = comma-joined name list); `true[i]` keeps rows where the column is true, `false[i]` where false, both true → no constraint |
81
+ | `{type: DG.FILTER_TYPE.FREE_TEXT, gridNames: ['age > 30', '* smith']}` | each entry is a row-matcher expression (`sex = "M"`, `height > 180`) or a `* text` wildcard over all columns; use this for computed / cross-column / OR conditions a single widget can't express; `value` only prefills the box, `column` is ignored |
82
+ | `{type: DG.FILTER_TYPE.SUBSTRUCTURE, column, molBlock}` | substructure (see below) |
83
+
84
+ For a single categorical pick like "show only females", use one
85
+ CATEGORICAL widget: `updateOrAdd({type: DG.FILTER_TYPE.CATEGORICAL, column: 'SEX', selected: ['F']})`.
86
+
87
+ For multi-column AND conditions ("age > 60 AND height < 170"), stack one
88
+ widget per column — they collaborate via `onRowsFiltering`, and the user can
89
+ adjust each condition in the panel.
90
+
91
+ **A UI FilterGroup filter applies asynchronously** — `t.filter` updates a frame
92
+ or two after `updateOrAdd`, not synchronously, so reading `t.filter.trueCount`
93
+ right after `updateOrAdd` sees the stale count; do not fall back to writing
94
+ `t.filter` directly.
95
+
96
+ ## Substructure filter
97
+
98
+ The `Chem:substructureFilter` widget reads `state.molBlock` — passing raw
99
+ SMILES or SMARTS into `molBlock` silently matches **zero** rows. Convert first.
100
+
101
+ - `DG.chem.isMolBlock(s)` — pure JS, cheap (`s.includes('M END')`).
102
+ - `DG.chem.isSmarts(s)` — calls `Chem:isSmarts` (requires the Chem package).
103
+ - Otherwise treat as SMILES.
104
+ - Convert with `DG.chem.convert(s, fromNotation, toNotation)`. Notations live
105
+ on `DG.chem.Notation` (`Smiles`, `Smarts`, `MolBlock`).
106
+
107
+ ```js
108
+ // SMILES or SMARTS → molblock → UI substructure filter.
109
+ const query = 'c1ccccc1';
110
+ const molBlock = DG.chem.isMolBlock(query)
111
+ ? query
112
+ : DG.chem.convert(query, DG.chem.isSmarts(query) ? DG.chem.Notation.Smarts : DG.chem.Notation.Smiles, DG.chem.Notation.MolBlock);
113
+ view.getFiltersGroup({createDefaultFilters: true}).updateOrAdd({
114
+ type: DG.FILTER_TYPE.SUBSTRUCTURE,
115
+ column: 'smiles',
116
+ molBlock,
117
+ });
118
+ ```
119
+
120
+ ## Clearing & inverting
121
+
122
+ **Polarity is the #1 footgun:** in `t.filter`, a `true` bit = row **visible**,
123
+ `false` = **hidden**. So "show every row" is `setAll(true)`; `setAll(false)`
124
+ hides everything.
125
+
126
+ ```js
127
+ // Show every row again. Disable the UI filter widgets so they don't
128
+ // immediately re-narrow the mask (they stay on screen, just inactive).
129
+ view.getFiltersGroup({createDefaultFilters: true}).setActive(false);
130
+ t.filter.setAll(true);
131
+ ```
132
+
133
+ ```js
134
+ // Invert the current mask. If UI filters are active they'll re-clobber the
135
+ // inversion on the next filter pass — disable the group first if you want it to persist.
136
+ t.filter.invert();
137
+ ```
138
+
139
+ ## Show-only vs drop-rows — the destructive split
140
+
141
+ | User says... | Code | Destructive? |
142
+ |---------------------------------------------|-----------------------------------------------------------------|--------------|
143
+ | "filter to X" / "show only X" / "hide ..." | `view.getFiltersGroup({createDefaultFilters:true}).updateOrAdd({type, column, ...})` (the matching widget) | no — hide-only |
144
+ | "give me a new table of just the filtered rows" | `t.clone(t.filter)` | no — clones the DF |
145
+ | "remove rows where X" / "drop rows where X" | tool `table_remove_rows`, `where`: `pred(i)` | **yes** — rows removed |
146
+ | "remove rows where X is missing" | tool `table_remove_rows`, `where`: `t.getCol('X').isNone(i)` — a missing value is neither `null` nor `NaN`, so test it with `isNone` | **yes** |
147
+ | "delete the currently-hidden rows" | tool `table_remove_rows`, `where`: `!t.filter.get(i)` | **yes** |
148
+
149
+ "Filter" / "show only" / "hide" is a **hide-only** (reversible) operation → the
150
+ Filters panel. The `table_remove_rows` tool records the removal for Ctrl+Z (`t.rows.removeWhereIdx` does not,
151
+ so do not use it on an open table). If the user says "remove"
152
+ or "delete", **confirm intent** when "filter" might be what they meant.
153
+
154
+ `t.clone(filter, columns?, withSelection?)` clones the visible rows. Pass an
155
+ array of column names to narrow the copy; pass `true` for `withSelection` to
156
+ carry the selection mask onto the clone.
157
+
158
+ ## Filter event lifecycle
159
+
160
+ | Event | When | Use for |
161
+ |----------------------|------------------------------------------------------------------------|-----------------------------------------------------------|
162
+ | `onRowsFiltered` | Filter pass complete; mask is now final. | Observers acting on the filtered result (count, summary). |
163
+ | `onFilterChanged` | Same as `df.filter.onChanged` — fires on any BitSet mutation. | Most general — works for direct writes too. |
164
+
165
+ In a viewer / widget, push subscriptions onto `viewer.subs` — `DG.Widget`
166
+ auto-cleans those on detach. In `datagrok_exec` code, push onto
167
+ `view.subs` to persist beyond the call.
168
+
169
+ ## Anti-patterns
170
+
171
+ 1. **Writing `t.filter` directly (`t.filter.init`, BitSet masks) for a user
172
+ filter** — bypasses the Filters panel and is overwritten next filter cycle.
173
+ Use `view.getFiltersGroup(...).updateOrAdd(...)`.
174
+ 2. **`t.filter.setAll(false)` to "clear" the filter** — hides every row. Use
175
+ `setActive(false)` on the group, or `t.filter.setAll(true)`.
176
+ 3. **Passing SMILES / SMARTS as raw `molBlock` to a `SUBSTRUCTURE` filter** —
177
+ RDKit silently returns zero matches. Convert via
178
+ `DG.chem.convert(query, DG.chem.Notation.Smiles, DG.chem.Notation.MolBlock)`.
179
+ 4. **Removing rows when the user said "filter"** — destructive.
180
+ Use the Filters panel for non-destructive "hide" intent.
181
+ 5. **`t.clone(t.filter)` to "filter the DF"** when the user wanted rows hidden —
182
+ allocates a new DF for nothing. Reach for it only when they actually want a
183
+ new DataFrame (export, downstream pipeline).
184
+ 6. **Treating `BitSet.invert()` like it returns a new BitSet** — it mutates
185
+ `this` and returns `this` for chaining.
@@ -0,0 +1,270 @@
1
+ ---
2
+ name: datagrok-grid-customization
3
+ description: Sort, hide, show, reorder, resize, pin, format, and color-code columns in a Datagrok TableView grid via the datagrok_exec tool. Use whenever the user asks to sort by a column (any direction), multi-sort, hide / show / reorder / pin / resize columns, freeze the first N columns, change number-format display, color-code cells (defaults and grid-only tint here; full per-type reference in datagrok-df-and-columns), set row height, or reset the grid back to defaults. Distinct from datagrok-df-and-columns (which owns column-level data metadata like semType, units, friendlyName, and is also where canonical color-coding lives) and from datagrok-viewers (which owns scatter plot / histogram / etc.). Does NOT cover filtering (`datagrok-filtering`), selection (`datagrok-selection`), custom cell renderer authoring (`create-cell-renderer`), saving / restoring layouts, or grid event handlers.
4
+ ---
5
+
6
+ # datagrok-grid-customization
7
+
8
+ Customize a Datagrok grid via the `datagrok_exec` tool using `view.grid`,
9
+ `grid.columns`, the per-`GridColumn` setters, and the data-side
10
+ `col.meta.colors` / `col.meta.format`.
11
+
12
+ Globals inside every `datagrok_exec` call: `grok`, `ui`, `DG`, `view`, `t`
13
+ (the active `DG.DataFrame` when `view` is a `TableView`).
14
+
15
+ Color coding is canonically data-side (`col.meta.colors.set*`) because it
16
+ propagates to every viewer that reads the column. `datagrok-df-and-columns`
17
+ owns the broader column-metadata picture.
18
+
19
+ ## Quick reference
20
+
21
+ | Need | API |
22
+ |-------------------------------|--------------------------------------------------------------------|
23
+ | Sort (single / multi) | `view.grid.sort(['name', 'mw'], [true, false])` |
24
+ | Clear sort | `view.grid.sort([], [])` |
25
+ | Hide one column | `view.grid.col('smiles').visible = false` |
26
+ | Show only these | `view.grid.columns.setVisible(['name', 'mw', 'logp'])` |
27
+ | Reorder columns | `view.grid.col('name').move(1)` per column (see *Visibility and order*) |
28
+ | Width (one column, pixels) | `view.grid.col('smiles').width = 250` |
29
+ | Width policy (all columns) | `view.grid.setColumnsWidthType(DG.ColumnWidthType.Optimal)` |
30
+ | Pin to left | `view.grid.col('smiles').pin()` |
31
+ | Unpin | `view.grid.col('smiles').unpin()` |
32
+ | Freeze first N visible | `view.grid.setOptions({frozenColumns: 2})` |
33
+ | Row height | `view.grid.setOptions({rowHeight: 28})` |
34
+ | Color coding (all types) | `col.meta.colors.set*` — no args = platform default; full reference in `datagrok-df-and-columns` |
35
+ | Turn off color coding | `col.meta.colors.setDisabled()` |
36
+ | Number format | `col.meta.format = '0.00'` |
37
+
38
+ ## Critical traps
39
+
40
+ 1. **`grid.sortByColumns = [...]` is a getter-only assignment.** Silent no-op.
41
+ Always call `grid.sort(columnNames, ascendingBooleans)` instead. The booleans
42
+ are `true = asc`, `false = desc`. The pair must be parallel.
43
+
44
+ 2. **`grid.columns.byIndex(0)` returns the row header,** not the first data
45
+ column. Loops start at index 1. Prefer `grid.col('name')` whenever you know
46
+ the name.
47
+
48
+ 3. **`gridCol.name = 'New Label'` renames the underlying DataFrame column** —
49
+ not a display rename. Every reference by the old name silently breaks.
50
+ For display-only rename, use `col.meta.friendlyName` (df-and-columns).
51
+
52
+ 4. **`view.resetLayout()` closes every viewer the user added.** Don't use it
53
+ for "clear sort" or "reset the grid". Reset selectively (see *Resetting*).
54
+
55
+ ## Data-side vs grid-side
56
+
57
+ | Need | Side | API |
58
+ |--------------------------------------------------------------|-------|-------------------------------------------------------------|
59
+ | Color cells so every viewer respects it | data | `col.meta.colors.setLinear/setCategorical/setConditional` (df-and-columns) |
60
+ | Color the grid column only (uniform tint) | grid | `gridCol.backColor = 0xFFFFEEEE` (rare) |
61
+ | Format numbers everywhere | data | `col.meta.format = '0.00'` |
62
+ | Format only in this grid | grid | `gridCol.format = '0.00'` |
63
+ | Hide a column (still in DF) | grid | `gridCol.visible = false` |
64
+ | Drop a column from the DF | data | `df.columns.remove(col)` (df-and-columns) |
65
+ | Display name across all viewers | data | `col.meta.friendlyName = 'Potency'` (df-and-columns) |
66
+ | Sort the grid | grid | `grid.sort(cols, bools)` |
67
+ | Pin / freeze | grid | `gridCol.pin()` or `grid.setOptions({frozenColumns: N})` |
68
+
69
+ Principle: **data-side (`col.meta.*`) for what semantically belongs to the
70
+ column; grid-side (`view.grid.*`) for this view's presentation only.**
71
+
72
+ ## Sorting
73
+
74
+ `grid.sort(columnNames, ascendingBooleans)`. Both arrays are parallel.
75
+ `true` is ascending, `false` is descending.
76
+
77
+ ```js
78
+ // Single column descending.
79
+ view.grid.sort(['activity'], [false]);
80
+ ```
81
+
82
+ ```js
83
+ // Multi-column: class asc, then activity desc.
84
+ view.grid.sort(['class', 'activity'], [true, false]);
85
+ ```
86
+
87
+ ```js
88
+ // Clear the sort.
89
+ view.grid.sort([], []);
90
+ ```
91
+
92
+ **Anti-pattern (silent failure):**
93
+
94
+ ```ts
95
+ // WRONG — getter-only, does nothing, throws nothing.
96
+ view.grid.sortByColumns = [t.col('activity')];
97
+ ```
98
+
99
+ `grid.sortByColumns` and `grid.sortTypes` read the live sort state. Assigning
100
+ to them is a no-op. The only way to apply a sort is `grid.sort(...)`.
101
+
102
+ ## Visibility and order
103
+
104
+ ```js
105
+ // Hide a single column.
106
+ view.grid.col('_internalId').visible = false;
107
+ ```
108
+
109
+ ```js
110
+ // Show only these (hides everything else).
111
+ view.grid.columns.setVisible(['SMILES', 'MW', 'LogP', 'activity', 'class']);
112
+ ```
113
+
114
+ ```js
115
+ // Re-order: SMILES first, then MW, then LogP. Use gridCol.move(position) per
116
+ // column. Index 0 is the row header, so the first data slot is 1. Apply the
117
+ // list in order: each move(i) inserts at that position.
118
+ view.grid.col('SMILES').move(1);
119
+ view.grid.col('MW').move(2);
120
+ view.grid.col('LogP').move(3);
121
+ ```
122
+
123
+ **Why not `grid.columns.setOrder([...])`?** It exists but does NOT move the listed
124
+ columns to the front — the listed columns retain their existing positions while
125
+ their *relative* order among each other is enforced (e.g., ApiTests' grid setOrder
126
+ test calls `setOrder(['race', 'age'])` and asserts race lands at `byIndex(4)`, not
127
+ `byIndex(1)`). For "put these columns first, in this order," use `move()` as above.
128
+
129
+ To re-show every hidden column, loop `grid.columns` from index 1 (index 0 is
130
+ the row header):
131
+
132
+ ```js
133
+ const cols = view.grid.columns;
134
+ for (let i = 1; i < cols.length; i++) {
135
+ const gc = cols.byIndex(i);
136
+ if (gc) gc.visible = true;
137
+ }
138
+ ```
139
+
140
+ ## Widths
141
+
142
+ ```js
143
+ // Per-column pixel widths.
144
+ view.grid.col('SMILES').width = 250;
145
+ view.grid.col('MW').width = 80;
146
+ ```
147
+
148
+ ```js
149
+ // Width policy for the whole grid. Values: Minimal | Compact | Optimal | Maximal.
150
+ view.grid.setColumnsWidthType(DG.ColumnWidthType.Optimal);
151
+ ```
152
+
153
+ `Minimal` fits just the label; `Compact` clamps narrower; `Optimal` matches
154
+ the widest visible value; `Maximal` expands to fill remaining space.
155
+
156
+ ## Pinning and freezing
157
+
158
+ `gridCol.pin()` pins on the left. No positional argument — pin in
159
+ left-to-right order. `gridCol.unpin()` reverses it.
160
+
161
+ ```js
162
+ view.grid.col('SMILES').pin();
163
+ view.grid.col('ID').pin(); // SMILES ends up leftmost.
164
+ ```
165
+
166
+ `frozenColumns` freezes the first N visible columns by position (different
167
+ mechanism from `pin()`; do not mix them in one view):
168
+
169
+ ```js
170
+ view.grid.setOptions({frozenColumns: 2});
171
+ ```
172
+
173
+ Reading pinning and sorting back (there is no `isPinned`): `frozenColumns` counts the row header, and pinned
174
+ columns come right after it.
175
+
176
+ ```js
177
+ const g = view.grid;
178
+ const pinned = Array.from({length: g.props.frozenColumns - 1}, (_, i) => g.columns.byIndex(i + 1).name);
179
+ const sort = g.sortByColumns.map((c, i) => `${c.name} ${g.sortTypes[i] ? 'asc' : 'desc'}`);
180
+ return {pinned, sort};
181
+ ```
182
+
183
+ ## Row height
184
+
185
+ ```js
186
+ // Tall rows — useful when rendering molecules or HTML in cells.
187
+ view.grid.setOptions({rowHeight: 100});
188
+ ```
189
+
190
+ ## Number / date format
191
+
192
+ `col.meta.format` writes a format tag the grid honors:
193
+
194
+ ```js
195
+ t.col('IC50').meta.format = '0.00';
196
+ t.col('count').meta.format = '#,##0';
197
+ ```
198
+
199
+ Common format strings: `'int'`, `'0.00'`, `'0.0000'`, `'#,##0.00'`,
200
+ `'compact'`, `'scientific'`, `'money'`, `'percent'`; dates: `'dd.MM.yyyy'`,
201
+ `'MMM d, yyyy'`, `'relative'`.
202
+
203
+ `gridCol.format = '0.00'` exists too — grid-only override. Use the data-side
204
+ `col.meta.format` unless the grid should display differently from other
205
+ consumers.
206
+
207
+ ## Color coding
208
+
209
+ The canonical reference — all four shapes (linear / categorical /
210
+ conditional / off), options, and traps — lives in the
211
+ **`datagrok-df-and-columns`** skill; load it for anything beyond the
212
+ rules below.
213
+
214
+ - No specific colors or rules requested → call the setter with **no
215
+ arguments** (`setLinear()` / `setCategorical()` / `setConditional()`) —
216
+ the platform's default scheme applies. Never invent a palette the user
217
+ didn't ask for.
218
+ - Turn off: `col.meta.colors.setDisabled()`.
219
+
220
+ Grid-only color (advanced): `view.grid.col('foo').backColor = 0xFFFFEEEE`
221
+ paints a uniform background in this grid only. Other viewers ignore it.
222
+ For value-based coloring, always use `col.meta.colors.set*` — a scatter plot
223
+ color axis on the same column will not pick up `gridCol.backColor` /
224
+ `gridCol.categoryColors`.
225
+
226
+ ## Resetting the grid
227
+
228
+ There is no single "reset grid" API. Combine the relevant primitives:
229
+
230
+ ```js
231
+ // Restore visibility (skip index 0 = row header), reset width policy, clear sort, drop color codings.
232
+ const cols = view.grid.columns;
233
+ for (let i = 1; i < cols.length; i++) {
234
+ const gc = cols.byIndex(i);
235
+ if (gc) gc.visible = true;
236
+ }
237
+ view.grid.setColumnsWidthType(DG.ColumnWidthType.Optimal);
238
+ view.grid.sort([], []);
239
+ for (const c of t.columns.toList())
240
+ c.meta.colors.setDisabled();
241
+ ```
242
+
243
+ This is the right pattern for "reset the grid customization but keep my
244
+ viewers". Do **not** call `view.resetLayout()` — it closes scatter plots,
245
+ histograms, filter panels the user added.
246
+
247
+ ## Guarding for non-TableView
248
+
249
+ `view.grid` is only present on `DG.TableView`. Script views and bare
250
+ `ViewBase` have no grid:
251
+
252
+ ```ts
253
+ if (!(view instanceof DG.TableView)) return;
254
+ ```
255
+
256
+ ## Out of scope
257
+
258
+ - **Custom cell renderer authoring** — see `create-cell-renderer`. From here,
259
+ `gridCol.cellType = 'Molecule'` attaches a registered renderer.
260
+ - **Viewer configuration** — `datagrok-viewers`.
261
+ - **Filtering and selection** — `datagrok-filtering`, `datagrok-selection`.
262
+ - **Layout save / restore** — `view.saveLayout()` / `view.loadLayout()`.
263
+ - **`grid.onCellPrepare` / `grid.onCellRender`** — powerful but abuse-prone.
264
+ One-line pointer:
265
+ ```ts
266
+ view.grid.onCellPrepare((gc) => {
267
+ if (gc.tableColumn?.name === 'activity' && gc.cell.value > 100)
268
+ gc.style.backColor = 0xFFFFCCCC;
269
+ });
270
+ ```