I am hiding the entire column in the grid like this?
$开发者_JAVA技巧('#Grid tr th').each(function(column) {
if ($(this).is('#div.id')) {
hide();
}
});
Can I do like this?
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
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.
let's say i want to hide the 17th col. of the grid
var colindex =16;
$("#CP_Main_gvPOItems").find("th:nth-child(" + colindex + "), td:nth-child(" + colindex + ")").hide();
精彩评论