Populating data for Lens Datatable
How to structure an API or mock function to respond to `_read` requests and return data for the Lens table.
📡 Writing an API for Lens DataTable
To enable the Lens DataTable to fetch and render data correctly, you need to implement a _read API endpoint for your data resource. Below are the required guidelines and response structure.
✅ Endpoint Format
The API should respond to a POST request at the following pattern:
:endpoint: is the endpoint defined in the Lens Provider Configuration.
📥 Request Body
The request body is a JSON object structured like this:
🔍 Filters Structure
The filters key follows a structured object format to support complex, nested filter conditions using logical operators. This enables powerful server-side filtering.
Here’s the format:
Keys:
op: Logical operator. Can beand,or, ornot.conditions: An array of filter conditions.attribute: The name of the attribute to filter (must match view config keys).op: Comparison operator. Examples include:is: Equalsis_not: Not equalsis_any_of: Attribute matches any in listcontains,starts_with,ends_withgreater_than,less_than, etc.
value: The value or array of values used for filtering.
You can nest conditions by including another filter object inside conditions.
This allows filters to be as expressive as needed while staying consistent.
📤 Response Structure
The response must return data in the following format:
data: Array of row entries.meta: Controls pagination and is required by the table.next_cursor: The next starting index for paginated fetch.count: Total number of records (optional but useful for UX).
⚙️ Row Structure
Each object in data should contain fields matching the attribute keys in the table configuration, including nested keys if applicable:
Ensure keys like city.locality.id are resolvable from the nested object. This structure supports selection keys and complex URL bindings in actions.
💡 Tips
- Pagination: Always respect the
cursorand returnnext_cursorto support infinite scroll or load-more. - Filtering: Use the
filtersobject to dynamically filter data based on selected filter values. - Search: Use the
searchstring to match against relevant columns in the dataset.