在数据表中使用行合并

3
{% raw %}

<table class="table table-striped table-bordered row" id="compare-table" style = "table-layout: fixed; margin-right: auto; margin-left: auto">
    <thead>
        <th class = "col-md-3 tableHeading">Configuration name</th>
        <th class = "col-md-3 tableHeading">Property Name</th>
        <th class = "col-md-3 tableHeading">Value 1</th>
        <th class = "col-md-3 tableHeading">Value 2 </th>
    </thead>
    <tbody>
    {{#each tableRows }}
        {{#each values}}
            <tr>
                {{#if @first}}
                <th  class="breakWord inlineHeading" rowspan={{../length}}>{{ ../pid }}</th>
                {{/if}}

                <td class="breakWord">{{ propName }}</td>
                <td class="breakWord">{{ propValueA }}</td>
                <td class="breakWord">{{ propValueB }}</td>
            </tr>
        {{/each}}
    {{/each}}
    </tbody>
</table>
{% endraw %}

我需要在ajax请求后动态渲染表格,并根据配置名称分组行。当我在Data Table中使用rowspan时,只会呈现简单的表格,并出现控制台错误:

jquery.dataTables.min.js:24 Uncaught TypeError:无法将未定义的属性'_DT_CellIndex'设置为

我正在使用handlebars.js来填充Table-Template

DATATABLE: https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"> https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js">

有没有一种方法可以在保持Datatable功能的同时以这种格式生成表格。

enter image description here


这里的 JavaScript 在哪里? - SamHoque
<th rowspan="2">名称</th> - Sumesh TG
@SumeshTG 我正在使用Handlebars动态设置rowspan,但是它会抛出控制台错误,并且只渲染了一个简单的HTML表格,没有分页、搜索和排序功能。 - shubham dua
@SamzSakerz 我直接使用CDN链接导入Datatable,并想知道如何使用rowspan,需要使用哪个JS。我对JS很新,希望能得到这个问题的帮助。如果帖子需要进行任何编辑,请建议。谢谢。 - shubham dua
1个回答

1

$(document).ready(function() {
   var table = $('#example').DataTable({
      'ajax': 'https://api.myjson.com/bins/qgcu',
      'rowsGroup': [2]
   });   
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.datatables.net/v/dt/dt-1.10.12/datatables.min.js"></script>
<script src="https://cdn.rawgit.com/ashl1/datatables-rowsgroup/fbd569b8768155c7a9a62568e66a64115887d7d0/dataTables.rowsGroup.js"></script>
<link href="https://cdn.datatables.net/v/dt/dt-1.10.12/datatables.min.css" rel="stylesheet"/>
<h3>jQuery DataTables - ROWSPAN in table body TBODY</h3>

<hr><br>
    
<table id="example" class="display" cellspacing="0" width="100%">
   <thead>
      <tr>
         <th>Name</th>
         <th>Position</th>
         <th>Office</th>
         <th>Extn.</th>
         <th>Start date</th>
         <th>Salary</th>
      </tr>
   </thead>
   <tfoot>
      <tr>
         <th>Name</th>
         <th>Position</th>
         <th>Office</th>
         <th>Extn.</th>
         <th>Start date</th>
         <th>Salary</th>
      </tr>
   </tfoot>
</table>

使用https://cdn.rawgit.com/ashl1/datatables-rowsgroup/fbd569b8768155c7a9a62568e66a64115887d7d0/dataTables.rowsGroup.js外部库,并在datatable配置中应用'rowsGroup': [index_of_column]。 希望这能帮到你。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接