Jump to content

Hide column/field in results page


Recommended Posts

Hi all --

I want to include an auto-incrementing ID in my search results because I want that to be the default sort order (especially to make a map mashup default to center on the first item in the table). But I don't want that field/column to display on the results page. Is there a way to hide it with JavaScript?

Thanks!

-- Mike

Link to comment
Share on other sites

  • 3 weeks later...

Hi Mike,

Here is an example of script that you can use to hide or modify the result table. Put it in the footer :

var stl='none'; // means hidden

var tbl = document.getElementsByTagName('table')[5]; // 5 means there are 4 tables in the html page before the caspio table

var rows = tbl.getElementsByTagName('tr');

for (var row=1; row

{

var cels = rows[row].getElementsByTagName('td');

cels[1].style.textAlign='center'; // aligns the second column

cels[2].style.textAlign='right';

cels[2].style.fontWeight ='bold';

cels[3].style.textAlign='right';

if (cels[4].innerHTML >= 1.2) // check the value in the 5th columns and change it in red if higher than 1.2

{cels[4].style.color='red'}

cels[6].innerHTML= Math.round(100*(cels[6].innerHTML-1))+'%'; // change the value in a percent based on a calculation

if (cels[6].innerHTML=='0%')

{cels[6].innerHTML=''}

cels[6].style.textAlign='center';

cels[7].style.display=stl; // hide the 8th column

}

Hope this helps. :)

Yves

Link to comment
Share on other sites

  • 1 month later...

Just saw this reply -- your code worked beautifully! I wanted to hide the first column, and this was all I needed:

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

-- Mike

Link to comment
Share on other sites

  • 6 years later...
  • 1 year later...
On 2/5/2009 at 0:50 AM, mdupras said:

Just saw this reply -- your code worked beautifully! I wanted to hide the first column, and this was all I needed:

 


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

Thanks!

-- Mike

 

Link to comment
Share on other sites

  • 8 months later...

Thanks for the above post. I have seen this solution in a few posts now. My problem is that my table has several 'pages' to it, and when I move to another page, the formatting does not carry over, so the columns become visible again. Any solutions for having this apply to all pages in the table when there are too many records to display all on one page? 

Link to comment
Share on other sites

  • 3 months later...

Try to use this code:

<script language="javascript" type="text/javascript">
var stl='none';
var tbl = document.querySelectorAll('table[id^="cbTable"]')[0]; 
var rows = tbl.getElementsByTagName('tr');
for (var row=1; row<rows.length;row++)
{
var cels = rows[row].getElementsByTagName('td');
cels[1].style.display=stl;
}

rows = tbl.getElementsByTagName('tr');
for (var row=0; row<rows.length;row++)
{
var cels = rows[row].getElementsByTagName('th');
cels[1].style.display=stl;
}
</script>

 

Please note that the index for column starts at zero(0). So, if you will applying this code you need to set the cels[] number properly of the column that you want to hide. Example: You have 3 columns and you want to hide the last column, the cels[] must be set like this:      cels[2]

 

Link to comment
Share on other sites

  • 4 years later...

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