转置(旋转)jQuery数据表

时间:2019-03-29 05:52:30

标签: jquery datatable transpose

由于默认的搜索选项,我的datable将返回一行。我想在不单击任何按钮(即页面加载)的情况下转置(旋转)此表

我尝试了Stackoverflow和Google的一些解决方案。但是我只能转置“表头”部分,“行”保持不变。这是我的HTML表格-

    <table id="q2" class="display" style="width:200%">
<thead>
    <tr>
        <th>Schema</th>
        <th>Table Name</th>
        <th>Last Update Time</th>
        <th>Last Update Job</th>
        <th>Update Responsible</th>
        <th>Table Type ID</th>
        <th>Table Usage ID</th>
        <th>Row Update ID</th>
        <th>Table Comment</th>
        <th>Table Source ID</th>
        <th>Connected</th>
        <th>User View</th>
        <th>Imaginary</th>
        <th>User Table Comment</th>
        <th>BI Service</th>
        <th>Business Owner</th>
        <th>Solution Owner</th>
    </tr>
</thead>
</table>

这是我的Jquery Datatable插件-

$(document).ready(function () {
            var query = getUrlVars()["query"];
            var table = $('#q2').removeAttr('width').dataTable({
                "search": {"search": query, 
                            "regex": false,
                            "smart": false},
                "ordering": true,
                "language": {"zeroRecords": "No records to display"},
                ajax: 'logapi.php?query=query_02',
                fixedHeader: true,
                deferRender: true,
                scroller: true,
                processing: 'Loading...',
                autowidth: true,
                responsive: false,
                orderClasses: false,
                columnDefs: [{ width: 100, targets: 0 }],
                fixedColumns: true

            });
            table
        .column(1).search("(^"+query+"$)",true,false)
        .draw();

        });

这是我尝试对表进行转置的Jquery。但这只是转置页眉部分-

$(document).ready(function () {
            var rows = $('#q2 tr');
  var r = rows.eq(0);
  var nrows = rows.length;
  var ncols = rows.eq(0).find('th,td').length;

  var i = 0;
  var tb = $('<tbody></tbody>');

  while (i < ncols) {
    cell = 0;
    tem = $('<tr></tr>');
    while (cell < ncols) {
      next = rows.eq(cell++).find('th,td').eq(0);
      tem.append(next);
    }
    tb.append(tem);
    ++i;
  }
  $('#q2').append(tb);
  $('#q2').show();
});

需要一些帮助来转置整个表格。

0 个答案:

没有答案