Column width not working in datatables bootstrap -
i using following code set column width of datatable. during partial page load width appears correct , when loads completely, width off.
<script> $(document).ready(function () { $("#membergrid").datatable({ "dom": 't<"clear">lfrtip', "tabletools": { "sswfpath": "../../content/swf/copy_csv_xls.swf" }, "destroy": true, "info": true, "blengthchange": false, "bfilter": false, "bautowidth": false, "aocolumns": [{ "swidth": "20%" }, { "swidth": "20%" }, { "swidth": "20%" }, { "swidth": "10%" }, { "swidth": "20%" }, { "swidth": "10%" }] }); }); </script>
table markup
<table class="group-grid table table-hover table-bordered table-responsive zebra-striped" id="membergrid"> <thead class="tablehead"> <tr> <th style="width: 20%">name</th> <th style="width: 20%">room with</th> <th style="width: 20%">extensions</th> <th style="width: 10%">travel protection</th> <th style="width: 20%">flying from</th> <th style="width: 10%">balance</th> </tr> </thead> <tbody> <tr class="tablerows"> <td style="width: 20%"><%# eval("travelers") %></td> <td style="width: 20%"><%# eval("roommates")%></td> <td style="width: 20%"><%# eval("extensions")%></td> <td style="width: 10%"><%# (string) eval("hastpp") == "y"? "yes" : "no"%></td> <td style="width: 20%"><%# eval("airport")%></td> <td style="width: 10%">$<%# eval("balance")%></td> </tr> </tbody> </table>
would nice see table in action, strong feeling pure matter of width of content. elements display: table-cell
try expand in order show as content possible without wrapping. example, width of <th>
has caption "travel protection", define 10% - need rather broad table show "travel protection" within 10%.
so overrule default word-wrap
, word-break
settings <th>
:
table.datatable thead tr th { word-wrap: break-word; word-break: break-all; }
a sort of demo (as said, cannot proof table irl) -> http://jsfiddle.net/9vbz7thp/
the best thing adjust content of <th>
's fits hardcoded widths.
if content of <td>
's grows large (typically loooong not breakable word) :
table.datatable tbody tr td { word-wrap: break-word; word-break: break-all; }
btw: not need define hardcoded widths in both <th>
, <td>
's. <td>
's automatically width corresponding <th>
.
Comments
Post a Comment