Jump to content

Hide table if criteria is met


Recommended Posts

I'm trying to hide a tabular report if a given comparison returns as false.  I have the below code that works to hide the table no matter the result:

<script language="javascript" type="text/javascript">
function hide_column(column_order)
{
     var tbl = document.getElementsByTagName("table")[0];
     var table_header = tbl.getElementsByTagName('th')[column_order];
     table_header.style.display=stl;
     var rows = tbl.getElementsByTagName('tr');
     for (var row=1; row<rows.length;row++)
        {     
            var cels = rows[row].getElementsByTagName('td');
            cels[column_order].style.display=stl;
        }
}

var stl='none';
hide_column(0);
hide_column(1);
hide_column(2);
hide_column(3);
hide_column(4);
hide_column(5);
hide_column(6);
</script>

 

However, If I'm adding a restriction

     var string = "[@authfield:Authentications_2_Region]",
     substring = "[@field:Location_2_Region_GL]";
     if(string.includes(substring)=false)

I don't know where to put it; I've tried putting it everywhere and can't get it to work right.  Full disclosure: I'm not good with Javascript and may be way off the mark on the formatting...I'm trying to piece this together with W3 Schools and Google.

Link to comment
Share on other sites

In case someone stumbles across this, I was able to get the solution to work using this string of code:

 

<script language="javascript" type="text/javascript">
     function hide_column(column_order)
{
     var str = '[@authfield:Authentications_2_Region]'; 
     var n = str.indexOf('[@field:Location_2_Region_GL]');
     if(n < 0){
     var tbl = document.getElementsByTagName("table")[0];
     var table_header = tbl.getElementsByTagName('th')[column_order];
     table_header.style.display=stl;
     var rows = tbl.getElementsByTagName('tr');
     for (var row=1; row<rows.length;row++)
        {     
            var cels = rows[row].getElementsByTagName('td');
            cels[column_order].style.display=stl;
        }
}
}
var stl='none';
hide_column(0);
hide_column(1);
hide_column(2);
hide_column(3);
hide_column(4);
hide_column(5);
hide_column(6);

</script>

 

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...