Jump to content

Hide Tabular Columns based on a Field Value


Recommended Posts

Hello! 

Just wanted to share this solution that I have made wherein the tabular column would show specific columns based on a field. You may also refer to the steps below:

1. Create a case when statement that will return a CSS code that hides columns. You may refer to this code:

CASE 

WHEN [@field:Type]= '2'

THEN ' 
#target table:nth-of-type(1) td:nth-of-type(2)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(2)  {display: none;}

#target table:nth-of-type(1) td:nth-of-type(3)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(3)  {display: none;}

#target table:nth-of-type(1) td:nth-of-type(4)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(4)  {display: none;}

#target table:nth-of-type(1) td:nth-of-type(6)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(6)  {display: table-cell;}

#target table:nth-of-type(1) td:nth-of-type(7)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(7)  {display: table-cell;}

#target table:nth-of-type(1) td:nth-of-type(8)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(8)  {display: table-cell;}
'

WHEN [@field:Type] = '1'

THEN '

#target table:nth-of-type(1) td:nth-of-type(2)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(2)  {display: table-cell;}

#target table:nth-of-type(1) td:nth-of-type(3)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(3)  {ddisplay: table-cell;}

#target table:nth-of-type(1) td:nth-of-type(4)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(4)  {display: table-cell;}

#target table:nth-of-type(1) td:nth-of-type(6)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(6)  {display: none;}

#target table:nth-of-type(1) td:nth-of-type(7)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(7)  {display: none;}

#target table:nth-of-type(1) td:nth-of-type(8)  {ddisplay: none;}
#target table:nth-of-type(1) th:nth-of-type(8)  {ddisplay: none;}
'

else '0'

end

2. Add a Header element and add the code below:

<style>

#target table:nth-of-type(1) td:nth-of-type(1)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(1)  {display: none;}
 
[@calcfield:1]

</style>
 
</header>
<div id="target">
<header>

The first set of code will depend on the position/place of your Calculated Field. If it is not the first element, you may change the second set of numbers. 

3. Add the code below on the footer element:
 

</footer>
</div>
<footer>

 

You may also check out it here: https://c7eru143.caspio.com/dp/f94390006c836a78af3e4018ba14

Link to comment
Share on other sites

  • 2 months later...
On 7/15/2022 at 5:14 PM, Flowers4Algernon said:

Hello! 

Just wanted to share this solution that I have made wherein the tabular column would show specific columns based on a field. You may also refer to the steps below:

1. Create a case when statement that will return a CSS code that hides columns. You may refer to this code:

CASE 

WHEN [@field:Type]= '2'

THEN ' 
#target table:nth-of-type(1) td:nth-of-type(2)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(2)  {display: none;}

#target table:nth-of-type(1) td:nth-of-type(3)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(3)  {display: none;}

#target table:nth-of-type(1) td:nth-of-type(4)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(4)  {display: none;}

#target table:nth-of-type(1) td:nth-of-type(6)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(6)  {display: table-cell;}

#target table:nth-of-type(1) td:nth-of-type(7)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(7)  {display: table-cell;}

#target table:nth-of-type(1) td:nth-of-type(8)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(8)  {display: table-cell;}
'

WHEN [@field:Type] = '1'

THEN '

#target table:nth-of-type(1) td:nth-of-type(2)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(2)  {display: table-cell;}

#target table:nth-of-type(1) td:nth-of-type(3)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(3)  {ddisplay: table-cell;}

#target table:nth-of-type(1) td:nth-of-type(4)  {display: table-cell;}
#target table:nth-of-type(1) th:nth-of-type(4)  {display: table-cell;}

#target table:nth-of-type(1) td:nth-of-type(6)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(6)  {display: none;}

#target table:nth-of-type(1) td:nth-of-type(7)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(7)  {display: none;}

#target table:nth-of-type(1) td:nth-of-type(8)  {ddisplay: none;}
#target table:nth-of-type(1) th:nth-of-type(8)  {ddisplay: none;}
'

else '0'

end

2. Add a Header element and add the code below:

<style>

#target table:nth-of-type(1) td:nth-of-type(1)  {display: none;}
#target table:nth-of-type(1) th:nth-of-type(1)  {display: none;}
 
[@calcfield:1]

</style>
 
</header>
<div id="target">
<header>

The first set of code will depend on the position/place of your Calculated Field. If it is not the first element, you may change the second set of numbers. 

3. Add the code below on the footer element:
 

</footer>
</div>
<footer>

 

You may also check out it here: https://c7eru143.caspio.com/dp/f94390006c836a78af3e4018ba14

   Hi,

Jus to add, you may refer to this link on how to hide (or do any other stylings) multiple sibling elements all at once:

 

Link to comment
Share on other sites

  • 3 weeks later...

Hi - Just an update, here are the other ways for you to hide column in the Tabular Report:

Without Download/Sort Options:

table[id*='cbTable'] > tbody > tr[class*='cbResultSetTableHeader'] > th:nth-child(1), td[class*='cbResultSetData']:nth-child(1){

    display:none !important;
  
}

With Download/Sort Options:

table[id*='FreezeTabularHeaderObj'] > tr[data-cb-name="header"] > th:nth-child(1), td[class*='cbResultSetData']:nth-child(1), #target table:nth-of-type(1) th:nth-of-type(1), #target table:nth-of-type(2) th:nth-of-type(1){

    display:none !important;
  
}

Replace 1 with the position order of column to be hidden.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...