Hi all!
This will detail how you can set up a table Klip, where the table is only shown based on certain conditions being met.
If you want, you can skip to the bottom, and download the example Klip code for your reference.
When in the Klip Editor, in the Advanced Tools(top left), view the Klip Source Code, paste this code and then update.
Here are the steps for how we get there;
1-Set up input control
First, we need to set up a User Input Control, which determines whether the value is being shown or not.
For our example;
Values: ARRAY("true,false")
Labels: ARRAY("show,hide")
2-Set up table columns
Set up the table columns, so that IF the variable is set to hide, then nothing is displayed.
Note that the first element of the array is the column header.
Eg;
Do something like this for all table columns.
3-Set table properties
Set the table Properties such that there is no table border, and also that it should not show a particular amount of rows;
Also, it should have no column headers.
4-Set table header styling(Optional)
This section is optional, but lets you set your table header to look different than the other ones(eg bolded, darker background), which it normally wouldn't since in Step 3 we removed column headers.
This would look like this;
Add a hidden data to the table,
-
and set the following formula;
Then, set your indicator conditions for each column;
Example Code
{
"title": "Hide Table Conditionally",
"id": "ca511cd6b151ea6bdc8c3dfed1ab7f0e",
"workspace": {
"datasources": [],
"dimensions": {
"w": 400
}
},
"appliedMigrations": {
"post_dst": true,
"separate_root_dsts": true
},
"components": [
{
"type": "input",
"id": "e35da332-56",
"displayName": "User Input Control",
"dstContext": {
"id": "dste35da33256",
"kid": "ca511cd6b151ea6bdc8c3dfed1ab7f0e"
},
"components": [
{
"type": "proxy",
"role": "values",
"id": "26005803-57",
"displayName": "Values",
"fmtArgs": {
"resultMetadata": {
"ignoreDateFormat": false,
"isAggregated": false,
"resultCount": 1
}
},
"formulas": [
{
"txt": "ARRAY(\"true,false\")",
"ver": 2
}
],
"data": [
[
"true",
"false"
]
],
"autoFmt": false
},
{
"type": "proxy",
"role": "labels",
"id": "9d7804fa-58",
"displayName": "Labels",
"fmtArgs": {
"resultMetadata": {
"ignoreDateFormat": false,
"isAggregated": false,
"resultCount": 1
}
},
"formulas": [
{
"txt": "ARRAY(\"show,hide\")",
"ver": 2
}
],
"data": [
[
"show",
"hide"
]
],
"autoFmt": false
}
],
"scope": 2,
"propName": "visible",
"inputType": 1,
"inputLabel": "Visibility"
},
{
"type": "table",
"id": "c7a26def-27",
"displayName": "Table",
"dstContext": {
"id": "dstc7a26def27",
"kid": "ca511cd6b151ea6bdc8c3dfed1ab7f0e"
},
"components": [
{
"type": "table_col",
"role": "tcol",
"id": "d9f22ce9-28",
"displayName": "Unnamed 1",
"size": "xx-small",
"fmt": "txt",
"fmtArgs": {
"resultMetadata": {
"ignoreDateFormat": false,
"isAggregated": false,
"resultCount": 1
},
"autoFmt": {
"fmtArgs": {},
"defaultAggregate": "COUNT",
"fmt": "txt"
}
},
"conditions": [
{
"predicates": [
{
"left": {
"cx": "7303948a-9"
},
"type": "contain",
"right": {
"raw": "Header"
}
}
],
"reactions": [
{
"value": "bold",
"type": "style"
},
{
"value": "cx-bgcolor_eee",
"type": "background-color"
}
]
}
],
"components": [],
"formulas": [
{
"txt": "IF(\n\t$visible,\n\tARRAY(\"Country,Canada,US,Mexico\"),\n\tBLANK(0)\n)\n\n",
"ver": 2
}
],
"data": [
[
"Country",
"Canada",
"US",
"Mexico"
]
],
"autoFmt": true,
"name": "Unnamed 1",
"index": 0,
"borderLeft": "1",
"borderRight": "1",
"customHeader": false
},
{
"type": "table_col",
"role": "tcol",
"id": "0c84a069-31",
"displayName": "Unnamed 2",
"size": "xx-small",
"fmt": "txt",
"fmtArgs": {
"resultMetadata": {
"ignoreDateFormat": false,
"isAggregated": false,
"resultCount": 1
},
"autoFmt": {
"fmtArgs": {},
"defaultAggregate": "COUNT",
"fmt": "txt"
}
},
"conditions": [
{
"predicates": [
{
"left": {
"cx": "7303948a-9"
},
"type": "contain",
"right": {
"raw": "Header"
}
}
],
"reactions": [
{
"value": "bold",
"type": "style"
},
{
"value": "cx-bgcolor_eee",
"type": "background-color"
}
]
}
],
"components": [],
"formulas": [
{
"txt": "IF(\n\t$visible,\n\tARRAY(\"Population,36 Million,323 Million,128 Million\"),\n\tBLANK(0)\n)",
"ver": 2
}
],
"data": [
[
"Population",
"36 Million",
"323 Million",
"128 Million"
]
],
"autoFmt": true,
"name": "Unnamed 2",
"index": 1,
"borderLeft": "1",
"borderRight": "1",
"customHeader": false
},
{
"type": "data_slot",
"role": "data",
"id": "7303948a-9",
"displayName": "Header?",
"fmt": "txt",
"fmtArgs": {
"autoFmt": {
"fmtArgs": {},
"defaultAggregate": "COUNT",
"fmt": "txt"
},
"resultMetadata": {
"ignoreDateFormat": false,
"isAggregated": false,
"resultCount": 1
}
},
"isDstRoot": false,
"formulas": [
{
"txt": "IF(\n\t$visible,\n\tARRAY(\"Header,x,x,x\"),\n\tBLANK(0)\n)\n\n",
"ver": 2
}
],
"data": [
[
"Header",
"x",
"x",
"x"
]
],
"autoFmt": true,
"name": "Header?"
}
],
"tableRowsType": "all",
"maxRows": 100000,
"showHeader": false,
"showBorder": false
}
]
}
Hope this helps you all!
Warm regards,
Joshua
_____________________________
Joshua Cohen-Collier
Technical Support Engineer, Klipfolio
2 comments
-
This is great! The data in the table in this example is a simple array. Is there a way to have the headers appear if your column's data is referencing a table-formatted datasource instead of an array for which you've manually entered data? I can get all of this to work but my columns' data is a @column reference and when I the visibility toggle is on, I'd like the header (which had previously been entered manually under properties, to re-appear too. Thanks for this tip!
-
Thanks for posting this solution, Josh! It's extremely helpful.
- One minor addition: In each table column's Properties tab, set Column Borders invisible to eliminate lines between the columns that appear when there's no data.
- And one question: Has anyone figured out how to add a border to the table when its contents are visible (but to make the border disappear when the table is empty)?