Show Hide Columns using bootstrap table

This bootstrap snippet called "Show Hide Columns using bootstrap table" was created to help web designers,
front-end developers and back-end developer save time. Use it in your project and build your app faster,
You can also download the HTML, CSS, and JS code

This is the HTML code for this bootstrap snippet

Copy, paste, change, customize and run the following HTML code to get a result like the one shown in the preview tab

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

<table class="table table-bordered">
  <thead>
    <tr>
      <th>#</th>
      <th id="click-me">Click Me</th>
      <th>Last Name</th>
      <th>Username</th>
      <th class="toggleDisplay">Th 1</th>
      <th class="toggleDisplay">Th 2</th>
      <th class="toggleDisplay">Th 3</th>
      <th class="toggleDisplay">Th 4</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
      <td class="toggleDisplay">Td 1</td>
      <td class="toggleDisplay">Td 2</td>
      <td class="toggleDisplay">Td 3</td>
      <td class="toggleDisplay">Td 4</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
      <td class="toggleDisplay">Td 1</td>
      <td class="toggleDisplay">Td 2</td>
      <td class="toggleDisplay">Td 3</td>
      <td class="toggleDisplay">Td 4</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
      <td class="toggleDisplay">Td 1</td>
      <td class="toggleDisplay">Td 2</td>
      <td class="toggleDisplay">Td 3</td>
      <td class="toggleDisplay">Td 4</td>
    </tr> 
  </tbody> 
</table>

This is the CSS code for this bootstrap snippet

Copy, paste, change, customize and run the following CSS code to get a result Like the one shown in the preview

body{margin-top:20px;}

.toggleDisplay {
  display: none;
}
.toggleDisplay.in {
  display: table-cell;
}
                                    

This is the JS code for this bootstrap snippet

Copy, paste, change, customize and run the following JS code to get a result Like the one shown in the preview

$("#click-me").click(function() {
    $(".table .toggleDisplay").toggleClass("in");
}); 

Information about this bootstrap snippet

Creator: Srinu Sirigiri

Bootstrap version: 3.3.6

Created: Nov 17th 2016, 05:42

Views: 2.4K

Rated 5/5 based on 2 reviews