Register identifier patterns
Datagrok allows you to easily register identifier patterns, attach handlers to them and detect them in text everywhere on the platform. For example, you can register a pattern for CHEMBL identifiers (CHEMBL followed by numbers), attach a handler to it that queries the database for the compound and retrieves its structure to display it in the tooltip or context panel.
Basic approach
The traditional way to register identifier patterns involves manually configuring both the pattern detection and the handler logic. While this approach gives you full control, it requires more boilerplate code and manual setup.
To register an identifier pattern using the basic approach, you need to modify the package.json file of your package (you can use existing or create a new package ) by adding your semantic type metadata with corresponding pattern regex.
{
"name": "@datagrok/chembl",
... package data
"meta": {
"semanticTypes": [
{
"semType": "CHEMBL_ID",
"description": "Compound id in the CHEMBL database",
"parsers": [{
"regexp": "CHEMBL\\d+"
}]
}
]
}
}
After you registered the pattern in your package and deployed it, Datagrok will identify it in text anywhere on the platform and highlight it.

Now you can register and attach the handler to the semantic type (CHEMBL_ID defined in package.json) to for example retrieve the compound structure from the database.
Create a class that extends DG.ObjectHandler and implement the following methods:
export class ChemblIdHandler extends DG.ObjectHandler {
get type(): string {return 'CHEMBL_ID';} // must return a semtype
isApplicable(x: any): boolean {// gets called for each object to check if it's applicable to this handler
return x instanceof DG.SemanticValue && x.semType == 'CHEMBL_ID';
}
renderInnerCard(x: any) {// inner function for querying the database and rendering the card
const id = (x as SemanticValue).value;
return ui.divV([
ui.h3(id),
ui.wait(async () =>
ui.bind(x, grok.chem.drawMolecule(await grok.functions.call('Chembl:chemblIdToSmiles', {id: id})))),
], {style: {width: '220px', height: '150px'}});
}
// gets called when object is coming 'Search everywhere' search and renders card for it
renderCard(x: any) {
return ui.card(this.renderInnerCard(x));
}
// gets called when object is hovered and renders tooltip for it
renderTooltip(x: any, context?: any): HTMLElement {
return this.renderInnerCard(x);
}
// gets called when object is clicked and renders properties for it in context panel
renderProperties(x: any, context?: any): HTMLElement {
return ui.panels.infoPanel(x).root; // retrieves property panels that are associated with the given semtype
}
}
Then you need to register the handler in the package.ts file of your package, specifically in the function that autostarts the package:
//tags: init, autostart
export function init() {
//Register handlers
DG.ObjectHandler.register(new ChemblIdHandler());
}
After deploying the package, Datagrok will use the handler to query the database and display the compound structure in the tooltip or context panel when you hover over or click on the CHEMBL identifier.

It also allows you to search for the CHEMBL identifier in the Search Everywhere bar and Datagrok will show the compound structure in the search results.

DB-explorer library
For identifiers tied to database tables, the DB-explorer library provides a significantly easier and more powerful way to register identifiers and create rich, interactive exploration experiences. Instead of manually writing handler code, you simply configure the library with your database structure, and it automatically:
- Registers identifier patterns and semantic types
- Creates handlers that query your database
- Builds interactive drill-down views using foreign key relationships
- Renders context panels with all related data from connected tables
This declarative approach eliminates boilerplate code and enables complex database exploration with minimal configuration. It's the recommended method for any identifier that maps to a database entity.

How it works
When you configure the DB-explorer library for your database, the system:
- Detects identifiers: Automatically recognizes identifier patterns (e.g.,
CHEMBL1234,DRUG_ID_5678) in your data using regular expressions. - Maps to semantic types: Associates each identifier pattern with a semantic type and links it to a specific column in a specific table within your database.
- Leverages database relationships: Uses the database's foreign key relationships and reference information to understand how tables connect.
- Enables drill-down exploration: When you click an identifier anywhere in Datagrok, the system automatically:
- Queries the database for the entity associated with that identifier
- Displays all related information from the primary table
- Shows all associated records from related tables (using foreign keys)
- Renders custom visualizations (molecules, images, etc.) where applicable
This creates a seamless exploration experience where users can navigate complex database schemas without writing queries or understanding the underlying table relationships.
Use cases
The DB-explorer library is particularly valuable for:
- Life sciences: Exploring compound IDs (like ChEMBL IDs), protein identifiers, or assay IDs across chemical databases
- Enterprise systems: Navigating customer IDs, order numbers, or product codes across multiple related tables
- Research databases: Drilling down through experiment IDs, sample codes, or publication references
- Any domain: Where data is spread across multiple related tables and users need to quickly explore connections
No-code configuration (DB Explorer editor)
You can configure DB-explorer without writing code directly from the Database Connection.
- Go to Browse > Databases > Connection of choice.
- Right-click a database connection.
- Select Configure Identifiers....
- In the dialog that appears, select the Schema where your identifiers are located (e.g.,
public) and click OK.

This opens the Database Explorer editor for that specific connection and schema. The editor allows you to define how Datagrok detects and displays identifiers for tables in this schema.
Main Interface
The editor lists all configuration categories in an accordion. You can expand each section to view, add, edit, or delete items.
- Import / Export JSON: Located at the bottom. Use these to backup your configuration or copy it to another environment.
- Save: Validates your configuration (checking for missing required fields) and saves it to the system.
Configuration Sections
Identifiers
This is the most important section. It defines the "Entry Points"—the semantic types that trigger DB Explorer.
- Semantic Type: The specific name used by Datagrok to tag this data (e.g.,
CHEMBL_ID). If you use an existing semantic type, Datagrok will use your configuration to display info panels for it. - Schema, Table & Column: The specific database table and column where this identifier can be found.
- Match Regexp: (Optional) A JavaScript regular expression to automatically detect this semantic type in imported data (e.g.,
^CHEMBL\d+$).- Test Regexp: Click the "test" link to verify your regex against sample data.
- Regexp Example: (Optional) Provides metadata for the detector, helping with autodetection performance and showing user-friendly examples in the search UI.
- Example: A valid ID (e.g.,
CHEMBL1234). - Non-Variable Part: The constant prefix (e.g.,
CHEMBL). - Regexp Markup: A display-friendly pattern (e.g.,
CHEMBL[0-9]+).
- Example: A valid ID (e.g.,

Joins
Joins allow you to pull in data from related tables when an identifier is clicked. This allows you to construct comprehensive "Cards" shown in tooltips without writing complex SQL queries.
- From Schema/Table/Column: The starting table (usually the one containing the identifier).
- To Schema/Table/Column: The related table to join.
- Select Columns: The most powerful part of the join configuration. You select which columns from the related table to include.
- You can alias columns (e.g., select
canonical_smilesand rename it tostructure) to make the output friendlier. - These selected columns become available for display in the context panel and tooltips.
- You can alias columns (e.g., select

Explicit References
Datagrok automatically detects foreign key relationships defined in the database schema. However, if your database lacks foreign keys, or if you need to link tables across different schemas, you can define Explicit References.
- Schema/Table/Column (Source) -> Ref Schema/Ref Table/Ref Column (Target).
- These references are used to build the "Links" section in the context panel, allowing users to drill down from one entity to related records.