Apply style to table in javascript

0

I have a table

   <div class="container-fluid" style="margin-left: -29px; margin-right: -29px">
        <!--Striped Rows-->
        <div class="row clearfix">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="card-panel" style="margin-top: -29px; ">
                    <div class="body table-responsive">
                       <table id="main_grid" class="table"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>

I'm loading it dynamically through the result of an AJAX:

 var myData = result
            for (var i = 0; i < myData.length; i++) {
                var obj = myData[i];

                rows += "<tr>";
                rows += "<th>Id</th>";
                rows += "<th>Nome</th>";
                rows += "</tr>";
                rows += "<tr>";
                //rows += " <th><img src=" + "../images/arrow_right.png" + ">" + obj.id + "</th>";
                rows += " <th>" + obj.id + "</>";
                rows += " <th>" + obj.nome + "</th>";
                rows += "</tr>";
            }

And trying to apply the style:

 <style>
        table {
            max-width: 140px;
        }

        td {
            width: 35px;
        }
    </style>

But it does not work, how should I load the style?

    
asked by anonymous 03.07.2017 / 14:56

1 answer

1

I think it's because after th (table title) you have to use the td (default cell) that is calling in style. And it has a tag lock that you did not put:

rows += "<tr>";
            //rows += " <td><img src=" + "../images/arrow_right.png" + ">" + obj.id + "</td>";
            rows += " <td>" + obj.id + "</td>";
            rows += " <td>" + obj.nome + "</td>";
            rows += "</tr>";
    
03.07.2017 / 16:00