javascript - Dynamically created bootstrap table loose spacing adjusting -
i have bootstrap table repeated twice in code: 1 created using html code , using dynamic javascript.
when use html, bootstrap works fine , table plotted accordingly.
whan use javascript create it, columns looses proportional spacing.
the result expect same in both code.
why dynamic created 1 not respect original spacing html created table has ? need both tables same...
does can me that.
original code:
<p>html table</p> <div class="table-responsive"> <table class="table table-striped table-bordered table-hover table-condensed small"> <thead> <tr> <th><strong>item</strong></th> <th><strong>description</strong></th> <th><strong>value</strong></th> </tr> </thead> <tr> <td>item01</td> <td>item02</td> <td>item03</td> </tr> <tr> <td>item11</td> <td>item12</td> <td>item13</td> </tr> <tr> <td>item21</td> <td>item22</td> <td>item23</td> </tr> </table> </div> <p>javascript table</p> <div id="mymenu"> </div> <script type="text/javascript"> $(document).ready(function () { /// /// main table /// var tablediv = $("<div class='table-responsive'>"); $('#mymenu').append(tablediv); var table = $("<div class='table table-striped table-bordered table-hover table-condensed small'>"); tablediv.append(table); /// /// table head /// html = "<thead>" + " <tr>" + " <th><strong>item</strong></th>" + " <th><strong>description</strong></th>" + " <th><strong>value</strong></th>" + " </tr>" + "</thead>"; var tablehead = $(html); table.append(tablehead); /// /// table data /// var gridrowcount = 5; (var rowcount = 0; rowcount < gridrowcount; rowcount++) { html = "<tr>"; (var fieldcount = 1; fieldcount < 4; fieldcount++) { var str = "item" + rowcount.tostring() + fieldcount.tostring(); html = html + "<td>" + str + "</td>"; } html = html + "</tr>"; alert(html); table.append($(html)); } }); </script> jsfiddle:
make following changes in code
var table = $("<table class='table table-striped table-bordered table-hover table-condensed small'>");
use table instead of div
it works
Comments
Post a Comment