tags:

views:

49

answers:

2

I am hiding the entire column in the grid like this?

//            $('#Grid tr th').each(function(column) {
//                if ($(this).is('#div.id')) {
//                    hide();
//                }
//            });

can I do like this?

thanks

+1  A: 

You can do like this:

 $('#Grid tr th').each(function() {
            if ($(this).attr('id') == "#div") {
                $(this).hide();
            }
        });

You may want to replace the #div with the one you are using.

Sarfraz
But its still showing me? initially I did visible false for that column once user select from hided column I need to make hideor I need to make read only for that column?thnks
kumar
"#div" wouldn't be in the attribute id, I think you meant "div"
fudgey
+2  A: 

I think you need to do something like:

$('#Grid tr').each(function() {
         $(this).find('td:eq(0)').hide();
});

Where the number in eq() is the column numbers index (starts from zero). You may also user :first or :last instead of :eq().

You may also use this approach:
for the first column:

$("#Grid td:first-child").hide();

for any column with index from 1 (!) in nth-child():

$("#Grid td:nth-child(1)").hide();

for last column:

$("#Grid td:last-child").hide();

For hiding also the title in thead you can use comma separated selectors:

$("#Grid tbody td:nth-child(2), #Grid thead th:nth-child(2)").hide();

or

$("#Grid tbody td:nth-child(1)").hide();
$("#Grid thead th:nth-child(1)").hide();

or for the first approach:

$('#Grid tr').each(function() {
         $(this).find('td:eq(0), th:eq(0)').hide();
});

see the updated example at: http://www.alexteg.se/stackoverflow/jquery_hide_table_column.html

alexteg
But its still showing me the first column.thanks
kumar
See the two approaches and the test page above. There must be something you are doing wrong, as it works fine for me.
alexteg
can we hide the jquery grid column with column name and contents?thanks
kumar
Sure, I have updated the post above and the testpage. Just use comma separation like in CSS. The jQuery selectors behave more or less like CSS3.
alexteg