I have a very long table with three columns. I would like to
<table> <tr><td>Column1</td><td>Column2</td></tr> <tr><td>Column1</td><td>Column2</td></tr> <tr><td>Start</td><td>Hiding</td></tr> <tr><td>Column1</td><td>Column2</td></tr> <tr><td>Column1</td><td>Column2</td></tr> <tr><td>Column1</td><td>Column2</td></tr> <tr><td>End</td><td>Hiding</td></tr> <tr><td>Column1</td><td>Column2</td></tr> <tr><td>Column1</td><td>Column2</td></tr> </table>
This is the result I'm trying to get with jQuery.
Column1 Column2 Column1 Column2 ...Show Full Table... Column1 Column2 Column1 Column2
I would like to use the jQuery show / hide function to minimize the table, but still show some of the top and bottom rows. The middle rows should be replaced with text like "Show full table", and when clicked it will expand to show the full table from start to finish.
What is the best way to do this in jQuery?
BTW I already tried to add the "Table_Middle" class to some of the rows, but it does not hide it completely, the space in which it was occupied is still there, and I do not have text to give the user a way to fully expand the table.
[EDIT] Added working HTML example based on Parand answer
The example below is a complete working example, you don’t even need to download jquery. Just paste into an empty HTML file.
It degrades nicely to show only the full table if Javascript is disabled. If Javascript is enabled, it hides the middle rows of the table and adds show / hide links.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Example Show/Hide Middle rows of a table using jQuery</title> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#HiddenRowsNotice").html("<tr><td colspan='2'> <a href='#'>>> some rows hidden <<</a></td></tr>"); $("#ShowHide").html("<tr><td colspan='2'><a href='#'>show/hide middle rows</a></td></tr>"); $("#HiddenRows").hide(); $('#ShowHide,#HiddenRowsNotice').click( function() { $('#HiddenRows').toggle(); $('#HiddenRowsNotice').toggle(); }); }); </script> </head> <body> <table> <tbody id="ShowHide"></tbody> <tr><th>Month Name</th><th>Month</th></tr> <tbody> <tr><td>Jan</td><td>1</td></tr> </tbody> <tbody id="HiddenRowsNotice"></tbody> <tbody id="HiddenRows"> <tr><td>Feb</td><td>2</td></tr> <tr><td>Mar</td><td>3</td></tr> <tr><td>Apr</td><td>4</td></tr> </tbody> <tbody> <tr><td>May</td><td>5</td></tr> </tbody> </table> </body> </html>
[EDIT] Add a link to your blog and working example.
jquery html html-table
Brian Boatright Oct 18 '08 at 16:22 2008-10-18 16:22
source share