Results 1 to 4 of 4

Thread: [RESOLVED] JS Hide column in table

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Resolved [RESOLVED] JS Hide column in table

    I have a page that has multiple tables on it. I need to be able to dynamically hide/show one of two columns on one table and need to show or hide 3 of 6 columns in another table and I need to do this without hiding columns in the other tables that are present.

    The code below hides the column and the header just fine in the first table.
    Code:
    $(' td:nth-child(3),th:nth-child(3)').hide();
    The problem is that it also hides columns in other tables which I do not want hidden.

    I tried adding a class to the table and use that in the call as in the line below
    Code:
    $('.general td:nth-child(3),th:nth-child(3)').hide();
    Same result where it does what I need in one table but hides stuff in other tables as well.

    I've been searching for a while now looking at lots of different examples of how to hide a column but have yet to find a way to restrict it to a specific table.

    Any tips?

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: JS Hide column in table

    I have also tried
    Code:
     $('#ITCase td:nth-child(3),th:nth-child(3)').hide();
    Where ITCase is the id of the table in question.

    This also correctly hides the column in the ITCase table but also hides columns in other tables.

    I need for it to hide either column 2 or 3 in table ITCase and columns 1,2 and 3 or columns 4,5 and 6 in table ITComponents and not hide any columns in the other tables that are on the page. The groups of columns to be hidden are determined based on the result of a query.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: [RESOLVED] JS Hide column in table

    Looks like I have it, I added the id to the th part as well and it looks to be only affecting the table desired.
    Code:
    $('#ITCase td:nth-child(3),#ITCase th:nth-child(3)').hide();

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [RESOLVED] JS Hide column in table

    I always filter "down" the DOM - this is two distinct branches coming off the TABLE. I would have done it with TWO $().hide() calls.

    Apparently by specifying the #ID, you pull it back UP the DOM, to then find the TH children.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width