Dynamic Columns
ToolJet allows users to dynamically set the columns of a Table component using a JSON value. This guide explains how to configure dynamic columns in ToolJet.
Using Dynamic Column
- Drag a Table component from the right-side component library onto the canvas.
- Populate the Table component with data by connecting it to a query.
- Toggle the Use dynamic column option.
- Enter JSON to define the Table's columns dynamically. For example:
{
"name": "Name",
"columnType": "string",
"key": "first_name",
"cellBackgroundColor": "#000",
"textColor": "#fff",
"isEditable": true,
"regex": "",
"maxLength": 20,
"minLength": 5,
"customRule": ""
}
This configuration displays a column labeled Name with editable string data restricted to lengths between 5 and 20 characters, with white text on a black background.
Displaying Different Table Schema Based on the Current User
You can use dynamic columns to display different table schemas depending on the current user. Let's look at an example with the below schema:
ID | Name | Department | Salary | Performance | Login |
---|
Here, two different schemas are to be displayed based on the current user.
For Admin:
ID | Name | Department | Salary | Performance | Login |
---|
For Employees:
ID | Name | Department | Login |
---|
-
To configure the schema as per the user, enable Use dynamic column property.
-
Use the following JSON logic to dynamically adjust the schema based on the current user's role:
{{globals.currentUser.groups.includes("admin") ? [
{ name: 'id', key: 'id', id: '1' },
{ name: 'Name', key: 'name', id: '2' },
{ name: 'Email', key: 'email', id: '3' },
{ name: 'Department', key: 'department', id: '4' },
{ name: 'Salary', key: 'salary', id: '5' },
{ name: 'Performance Rating', key: 'performance', id: '6' },
{ name: 'Last Login', columnType:"datePicker", key: 'login', id: '7' }
] : [
{ name: 'id', key: 'id', id: '1' },
{ name: 'Name', key: 'name', id: '2' },
{ name: 'Email', key: 'email', id: '3' },
{ name: 'Department', key: 'department', id: '4' },
{ name: 'Last Login', columnType:"datePicker", key: 'login', id: '5' }
]}}