简体   繁体   中英

Hide one bootstrap table header

My table header is looking like this:-

 <div role="tabpanel" class="tab-pane" id="missed-entries"> <div class="container"> <div class="panel panel-info" style="margin-top:24px;"> <div class="panel-heading"> <h3 class="panel-title">Info</h3> </div> <div class="panel-body">blahh</div> </div> <table id="scale_missed_entries" data-toggle="table" data-pagination="true" > <thead> <tr> <th id="hidethis" data-field="product_id">ID</th> <th data-field="product_weight">Weight</th> <th data-field="product_added_date">Added date</th> <th data-field="button">Image</th> </tr> </thead> </table> </div> </div> 

I want to full hide this entire ID column with the id="hidethis".

What I tried :

<th id="hidethis" data-field="product_id" style="display:none;">ID</th>

this didn't do anything, I think that css cannot be used like that in a th.

$('hidethis').hide();

No impact with that jquery also.

$('td:nth-child(2),th:nth-child(2)').hide();

The closest success I had with this, but that only hidden my Image th, but all my buttons remained there.

I will also put a picture:

在此处输入图片说明

I want to full hide all of the marked with red.

I've tried to make my code as easy as possible and also included some comments.

I would consider using a class instead of an id though. :)

 // Save index (position) of th const cellIndex = $('#hidethis').index(); // Hide th first $('#hidethis').hide(); // Iterate over each table row $('#scale_missed_entries tbody tr').each(function () { // Select the cell with same index (position) as the table header const cell = $(this).children('td').get(cellIndex); // Hide 'em $(cell).hide(); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div role="tabpanel" class="tab-pane" id="missed-entries"> <div class="container"> <div class="panel panel-info" style="margin-top:24px;"> <div class="panel-heading"> <h3 class="panel-title">Info</h3> </div> <div class="panel-body">blahh</div> </div> <table id="scale_missed_entries" data-toggle="table" data-pagination="true"> <thead> <tr> <th id="hidethis" data-field="product_id">ID</th> <th data-field="product_weight">Weight</th> <th data-field="product_added_date">Added date</th> <th data-field="button">Image</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> </tbody> </table> </div> </div> 

Simply using CSS

 [data-field="product_id"] { display: none; } tr td:nth-of-type(1) { display: none; } 
 <div role="tabpanel" class="tab-pane" id="missed-entries"> <div class="container"> <div class="panel panel-info" style="margin-top:24px;"> <div class="panel-heading"> <h3 class="panel-title">Info</h3> </div> <div class="panel-body">blahh</div> </div> <table id="scale_missed_entries" data-toggle="table" data-pagination="true"> <thead> <tr> <th id="hidethis" data-field="product_id">ID</th> <th data-field="product_weight">Weight</th> <th data-field="product_added_date">Added date</th> <th data-field="button">Image</th> </tr> <tr> <td>1 </td> <td>10 </td> <td>100 </td> <td>1000 </td> </tr> </thead> </table> </div> </div> 

As i commented also apply a same class to th and there corresponding values <td> and hide them. it will work.

 $('.hidethis').hide(); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div role="tabpanel" class="tab-pane" id="missed-entries"> <div class="container"> <div class="panel panel-info" style="margin-top:24px;"><div class="panel-heading"> <h3 class="panel-title">Info</h3> </div><div class="panel-body">blahh</div></div> <table id="scale_missed_entries" data-toggle="table" data-pagination="true" > <thead> <tr> <th class="hidethis" data-field="product_id">ID</th> <th data-field="product_weight">Weight</th> <th data-field="product_added_date">Added date</th> <th data-field="button">Image</th> </tr> </thead> <tbody> <tr> <td class="hidethis" data-field="product_id">112</td> <td data-field="product_weight">51</td> <td data-field="product_added_date">2017-10-11</td> <td data-field="button">hi1</td> </tr> <tr> <td class="hidethis" data-field="product_id">111</td> <td data-field="product_weight">50</td> <td data-field="product_added_date">2017-10-10</td> <td data-field="button">hi</td> </tr> </tbody> </table> </div> </div> 

Note:- without jquery also you can now hide then through css:-

.hidethis{
  display:none; // or visibility:hidden;
}

Just use this

#scale_missed_entries th:nth-child(1) {
display: none;
}

edit based on the coment

To hide entire column use this--

#hidethis{
display:none;
}

  #myTable th:nth-child(1) { display: none; } #hidethis{ display:none; } 
 <div role="tabpanel" class="tab-pane" id="missed-entries"> <div class="container"> <div class="panel panel-info" style="margin-top:24px;"><div class="panel-heading"> <h3 class="panel-title">Info</h3> </div><div class="panel-body">blahh</div></div> <table id="scale_missed_entries" data-toggle="table" data-pagination="true"> <thead> <tr> <th id="hidethis" data-field="product_id">ID</th> <th data-field="product_weight">Weight</th> <th data-field="product_added_date">Added date</th> <th data-field="button">Image</th> </tr> <tr> <td id="hidethis">1 </td> <td>10 </td> <td>100 </td> <td>1000 </td> </tr> </thead> </table> </div> </div> 

Add:

#hidethis { display: none; }

to your css:

 #hidethis { display: none; } 
 <div role="tabpanel" class="tab-pane" id="missed-entries"> <div class="container"> <div class="panel panel-info" style="margin-top:24px;"> <div class="panel-heading"> <h3 class="panel-title">Info</h3> </div> <div class="panel-body">blahh</div> </div> <table id="scale_missed_entries" data-toggle="table" data-pagination="true"> <thead> <tr> <th id="hidethis" data-field="product_id">ID</th> <th data-field="product_weight">Weight</th> <th data-field="product_added_date">Added date</th> <th data-field="button">Image</th> </tr> </thead> </table> </div> </div> 

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM