html - How to make use of correct Responsive Table with rowspan in Mobile using jQuery? -
i facing problem in making responsive table. want result like:
i not know how make responsive using jquery. simple tables single rows in thead, js code responsive. here there 2 rows in thead.
please give me views , me out.
$('.demo').addclass('responsivetable').find('tr td').each(function() { $(this).find('td').each(function(index, value) { var $thistd = $(this); var $closesttable = $thistd.closest('table'); if ($closesttable.find('th').length) { $thistd.addclass('col' + index).attr('data-head', $.trim($closesttable.find('th:eq(' + index + ')').text() + '')); } else { $thistd.addclass('col' + index).attr('data-head', $.trim($closesttable.find('td:eq(' + index + ')').text() + '')); } }).last().addclass('tdlast'); });
.demo{ background-color: #fff;border: 1px solid #888;border-collapse: collapse;border-radius: 3px;box-shadow: 0 2px 0 #ccc;margin: 20px 0;overflow: hidden; } .demo th{background: rgba(0, 0, 0, 0) linear-gradient(to bottom, #3f6cff 0%, #698cfe 100%) repeat scroll 0 0;border-bottom: 1px solid #888;padding: 10px 0;text-align:center; } .demo th h3{ margin:0; color:#000; font-size:14px;} .demo tr:nth-child(2n+1) td{ background-color: #e5f2ff; } .demo tr td{ border-right: 1px solid #bbb; } .demo td{ border-bottom: 1px solid #888; padding: 10px; transition: 200ms ease 0s; } .demo tr:hover td{ background-color: rgb(244, 116, 1); } @media screen , (max-width:767px){ .demo, .demo tbody, .demo tbody tr, .demo tbody tr td{ display:block!important; width:100%!important;} .demo thead{ display:none !important; } .demo tbody tr td{ position:relative; padding-left:50%; border-bottom:1px solid #ccc; text-align: left;} .demo tbody tr td:before{ content:attr(data-head); position:absolute; top:0; left:0; width:50%; text-align: left; padding: 5px; font-weight:bold;} .demo tbody tr td:last-child{ border-bottom:none;} .demo tbody tr td p{ margin:0;} }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <table border="1" cellpadding="0" cellspacing="0" class="demo" width="800" align="center"> <thead> <tr> <th colspan="2">finance</th> <th colspan="2">accounting</th> </tr> <tr> <th valign="top"><strong><em>percentage of respondents</em></strong></th> <th valign="top"><strong><em>education level required</em></strong></th> <th valign="top"><strong><em>percentage of respondents</em></strong></th> <th valign="top"><strong><em>education level required</em></strong></th> </tr> </thead> <tbody> <tr> <td valign="top"><p align="center"> 84%</p></td> <td valign="top"><p align="center"> bachelors</p></td> <td valign="top"><p align="center"> 5%</p></td> <td valign="top"><p align="center"> associate degree</p></td> </tr> <tr> <td valign="top"><p align="center"> 16%</p></td> <td valign="top"><p align="center"> masters</p></td> <td valign="top"><p align="center"> 79%</p></td> <td valign="top"><p align="center"> bachelors</p></td> </tr> <tr> <td valign="top"><p align="center"> </p></td> <td valign="top"><p align="center"> </p></td> <td valign="top"><p align="center"> 5%</p></td> <td valign="top"><p align="center"> masters</p></td> </tr> </tbody> </table>
Comments
Post a Comment