ToolJet/docs/versioned_docs/version-2.33.0/how-to/conditionally-format-table.md

132 lines
6.4 KiB
Markdown
Raw Normal View History

Release: Community changes (v2.34.0) (#9226) * add custom resolvers info and editable row selection info (#9057) * fix system requirements icon * add auth info for webhooks and fix casing * add regex custom validation info (#9068) * [docs]: Marketplace 1.7 updates (#9085) * [docs] Amazon redshift plugin * make minor improvements * add and update docs for marketplace 1.7 * update order of plugins in overview to match sidebar * create new version --------- Co-authored-by: Shubhendra <withshubh@gmail.com> * add the latest version in the versions.json file (#9094) * [docs]: Update PDF component (#9088) * update PDF component * merged with develop and added changes to the new version * update docs favicon: (#9118) * [docs] SSO revamp (#9031) * add method to set default language * update image settings through custom css and update screenshots for getting started and tooljet concepts (#9158) * fix read documentation button * fix formatting for setup icons (#9172) * fix sidebar link for aws lambda * Update static media (#9175) * updated the screenshots * reduced the gif size * reverted the package.json file * edited the zoomed in images and replaced some gifs with screenshots * removed one gif * update static media * update file names * update toolbar * fix file names * fix: dynamodb img path * update media for org management dashboard * fix: casing and formatting * update workspace constant media * update media in workspace settings and github * update github sso * minor change to github sso docs * minor fix * update google sso * change includeCurrentVersion flag to false --------- Co-authored-by: Asjad Ahmed Khan <iitasjad2001@gmail.com> Co-authored-by: Asjad Ahmed Khan <60435499+2001asjad@users.noreply.github.com> Co-authored-by: Karan Rathod <karan.altcampus@gmail.com> * Feature: Engagespot plugin (#9012) * feat(plugins): added engagespot plugin * feat(docs): added engagespot plugin docs * chore(engagespot-plugin): revised copywritings * Feature: Databricks data source (#9174) * plugin-created * Databricks integration * icon, error handling * removed unrelated changes from marketplace and frontend package-lock.json removed runAsync and maxRows timeouts pending * timeout implementation * socket timeout and error handling * resolve comments * resolve comments2 * solved render issue test connection improvements * solved undefined error * fix TJDB not null value fail for is operation (#9055) * fix TJDB not null value fail for is operation * handling not null and null case insenstive values * Support for marketplace plugin deploy on render preview app (#9221) * Fix for marketplace error on render preview app * add marketplace build command * Adding new workflow for building marketplace plugin * removed render app creation * [:docs] Add documentation for Databricks plugin (#9224) * add docs for databricks * update databricks docs * update docs * remove ref to clusters * bump to v2.34.0 * Fixed data source cypress failure (#9227) * updated spec with required text * updated mongodb and import spec * updated import spec --------- Co-authored-by: Karan Rathod <karan.altcampus@gmail.com> Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com> Co-authored-by: Midhun G S <gsmithun4@gmail.com> Co-authored-by: Shubhendra <withshubh@gmail.com> Co-authored-by: Aman Regu <amanregu@gmail.com> Co-authored-by: Asjad Ahmed Khan <iitasjad2001@gmail.com> Co-authored-by: Asjad Ahmed Khan <60435499+2001asjad@users.noreply.github.com> Co-authored-by: Jobin Jose <129726530+jobin-logidots@users.noreply.github.com> Co-authored-by: Syed Mohammad Akhtar Rizvi <85864291+ShazanRizvi@users.noreply.github.com> Co-authored-by: blank0537 <111295371+blank0537@users.noreply.github.com> Co-authored-by: Mekhla Asopa <59684099+Mekhla-Asopa@users.noreply.github.com>
2024-03-29 13:43:26 +00:00
---
id: conditionally-format-table
title: Conditional Formatting in Table
---
Conditional formatting enhances the visual representation of data by allowing you to dynamically adjust the appearance of cells in table component based on specific conditions. This how-to guide will guide you through the process of implementing advanced conditional formatting for text color and background color in a Table component.
## Create a New Application and Set Up Data Source
1. Create a new application and add a Table component to the canvas.
2. Open the Query Panel at the bottom and click on the `+ Add` button.
3. Choose REST API as your data source and set the method to GET.
4. Enter the following URL as REST API endpoint:
```bash title="REST API Endpoint"
https://fakestoreapi.com/products
```
5. Click on the **Preview** button to view the data. Execute the query by clicking on the **Run** button.
<div style={{textAlign: 'center'}}>
<img style={{ border:'0', marginBottom:'15px', borderRadius:'5px', boxShadow: '0px 1px 3px rgba(0, 0, 0, 0.2)' }} className="screenshot-full" src="/img/how-to/conditionally-format/query.png" alt="Table Component With Data" />
</div>
## Display Data on the Table
1. Hide the Query Panel and click on the Table component to open its properties panel.
2. Under **Table Data**, enter the following code:
```js title="Table Data"
{{queries.restapi1.data}}
```
<div style={{textAlign: 'center'}}>
<img style={{ border:'0', marginBottom:'15px', borderRadius:'5px', boxShadow: '0px 1px 3px rgba(0, 0, 0, 0.2)' }} className="screenshot-full" src="/img/how-to/conditionally-format/tabledata.png" alt="Table Component With Data" />
</div>
## Enabling Conditional Formatting
1. Go to the **Columns** property of the Table component.
2. Select the column for which you want to enable conditional formatting (e.g., category).
3. If the column type is set to `Default` or `String`, you can set the conditional formatting for **text color** and **cell background color**.
**Note**: Only `cellValue` and `rowData` can be used as identifiers for conditional formatting.
<div style={{textAlign: 'center'}}>
<img style={{ border:'0', marginBottom:'15px', borderRadius:'5px', boxShadow: '0px 1px 3px rgba(0, 0, 0, 0.2)' }} className="screenshot-full" src="/img/how-to/conditionally-format/column.png" alt="Table Component With Data" />
</div>
## Conditional Formatting using Cell Value
### Example 1: Changing Text Color Based on Cell Value
1. Select the `Rate` column which has a column type of `Default`/`String`. This column contains the rating of each product on a scale of 1 to 5.
2. Under the **Text Color** propert, enter the following condition:
```js
{{cellValue < 2 ? 'red' : cellValue > 2 && cellValue < 3 ? 'Orange' : 'green'}}
```
The above condition will change the text color to red if the cell value is less than 2, orange if the cell value is greater than 2 and less than 3, and green if the cell value is greater than 3.
<div style={{textAlign: 'center'}}>
<img style={{ border:'0', marginBottom:'15px', borderRadius:'5px', boxShadow: '0px 1px 3px rgba(0, 0, 0, 0.2)' }} className="screenshot-full" src="/img/how-to/conditionally-format/textcv.png" alt="Table Component With Data" />
</div>
### Example 2: Changing Cell Background Color Based on Cell Value
- Select the `Rate` column, enter the following condition under the **Cell Background Color** property:
```js
{{cellValue >= 4 ? 'lightgreen' : cellValue >= 3 ? 'lightyellow' : 'lightcoral'}}
```
The above condition will change the cell background color to lightgreen if the cell value is greater than or equal to 4, lightyellow if the cell value is greater than or equal to 3, and lightcoral if the cell value is less than 3.
<div style={{textAlign: 'center'}}>
<img style={{ border:'0', marginBottom:'15px', borderRadius:'5px', boxShadow: '0px 1px 3px rgba(0, 0, 0, 0.2)' }} className="screenshot-full" src="/img/how-to/conditionally-format/cellcv.png" alt="Table Component With Data" />
</div>
## Conditional Formatting using Row Data
### Example 1: Changing Text Color Based on Row Data
- Select the `Title` column, enter the following condition under the **Text Color** property:
```js
{{rowData.price > 50 ? '#D9534F' : (rowData.rating.rate >= 4 ? '#5CB85C' : rowData.rating.rate >= 3 ? '#F0AD4E' : '#D9534F' )}}
```
The above condition will change the text color of the `Title` based on the value of the `price` and `rating` columns. If the value in the `price` column is greater than 50, the text color will be red. If the value in the `rating` column is greater than or equal to 4, the text color will be green. If the value in the `rating` column is greater than or equal to 3, the text color will be yellow. Otherwise, the text color will be red.
<div style={{textAlign: 'center'}}>
<img style={{ border:'0', marginBottom:'15px', borderRadius:'5px', boxShadow: '0px 1px 3px rgba(0, 0, 0, 0.2)' }} className="screenshot-full" src="/img/how-to/conditionally-format/textrd.png" alt="Table Component With Data" />
</div>
### Example 2: Changing Cell Background Color based on Row Data
- In this example, we will change the cell background color of the `Title` column based on the category of the product.
- Select the `Title` column, enter the following condition under the **Cell Background Color** property:
```js
{{rowData.category === "electronics" ? 'cyan' : rowData.category === "jewelery" ? 'pink' : 'lightgray'}}
```
The above condition will change the cell background color of the `Title` column based on the value of the `category` column. If the value in the `category` column is `electronics`, the cell background color will be cyan. If the value in the `category` column is `jewelery`, the cell background color will be pink. Otherwise, the cell background color will be lightgray.
<div style={{textAlign: 'center'}}>
<img style={{ border:'0', marginBottom:'15px', borderRadius:'5px', boxShadow: '0px 1px 3px rgba(0, 0, 0, 0.2)' }} className="screenshot-full" src="/img/how-to/conditionally-format/cellrd.png" alt="Table Component With Data" />
</div>
---
By following these steps, you can implement advanced conditional formatting for text color and cell background color in your Table component. Experiment with different conditions and color combinations to create visually appealing and informative tables in your applications.