简体   繁体   English

在页面上平均分配表列

[英]Distribute table columns equally over the page

I have a content placed in a table: 我有一个放在桌子上的内容:

<table class="table table-hover" id="anliegenGrammatik"></table>

and this is my jQuery where I have AJAX request and using the response I populate (append) the table above. 这是我的jQuery,我有AJAX请求,并使用填充(添加)上表的响应。

success: function(response) {
    $.each(response, function(index) {
        $.each(response[index].synonyms, function(index2) {
            $('#anliegenGrammatik').append('<tr> <td>' + response[index].synonyms[index2] + '</td> </tr>');
        });
    });
},

But it has a lot of data and like this it produces several hundred rows. 但是它有很多数据,像这样它会产生数百行。 How can I make in jQuery that it distributes columns and rows equally over the page. 我如何在jQuery中使其在页面上平均分配列和行。 For example, instead of having one <tr> with 100 <td> s, I would like to have 4 <tr> and 25 <td> s in each row. 例如,代替具有一个<tr> 100 <td> S,我想有4 <tr>和25 <td>每一行中第

Is this even possible? 这有可能吗?

 success: function(response) { $.each(response, function(index) { var item = 1; var totalItems = response[index].synonyms.length; var numRows = 4; // number of rows var cellsRow = Math.floor(totalItems/numRows); // number of cells per row var cells = ''; $.each(response[index].synonyms, function(index2) { cells += '<td>' + response[index].synonyms[index2] + '</td>'; if((item % cellsRow == 0) || item == totalItems) { $('#anliegenGrammatik').append('<tr>'+cells+'</tr>'); cells = ''; } item ++; }); }); }, 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM