I combined some tools to create responsive tables for phones and I thought I'd share. Maybe someone can help me turn this into a plugin. To create it I used http://css-tricks.com/responsive-data-tables/ and http://twitter.github.com/bootstrap/scaffolding.html#responsive.
My Css
I added a fnCreatedCell callback to each column to add a label only visible on the phone. I'm using angularjs so the reference to the column title comes my code.
The table ends up working like http://css-tricks.com/examples/ResponsiveTables/responsive.php.
I also added "sClass" .visible-desktop for columns I wanted to hide on tablets and phones or .hidden-tablet or .hidden-phone to hide just on one or the other.
My Css
@media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) { /* Force table to not be like tables anymore */ .dataTable > table, thead, tbody, th, td, tr { display: block; } /* Hide table headers (but not display: none;, for accessibility) */ .dataTable > thead tr { position: absolute; top: -9999px; left: -9999px; } .dataTable > tr { border: 1px solid #ccc; } .dataTable > td { /* Behave like a "row" */ border: none; border-bottom: 1px solid #eee; position: relative; padding-left: 50%; } .dataTable > td:before { /* Now like a table header */ position: absolute; /* Top/left values mimic padding */ top: 6px; left: 6px; width: 45%; padding-right: 10px; white-space: nowrap; } }
I added a fnCreatedCell callback to each column to add a label only visible on the phone. I'm using angularjs so the reference to the column title comes my code.
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) { $(nTd).html("<span><strong class='visible-phone'>" + $scope.contactsColumns[iCol].sTitle + ":</strong> " + $(nTd).html() + '</span>'); }
The table ends up working like http://css-tricks.com/examples/ResponsiveTables/responsive.php.
I also added "sClass" .visible-desktop for columns I wanted to hide on tablets and phones or .hidden-tablet or .hidden-phone to hide just on one or the other.