【问题标题】:Using row span in Data Tables在数据表中使用行跨度
【发布时间】:2018-12-12 06:26:18
【问题描述】:
{% 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: Cannot set property '_DT_CellIndex' of undefined

我正在使用 handlebars.js 来填充表格模板

数据表: 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 功能的同时以这种格式生成表格。

【问题讨论】:

  • 这里面的javascript在哪里?
  • &lt;th rowspan="2"&gt;Name&lt;/th&gt;试试
  • @SumeshTG 我正在通过车把动态提供行跨度,但它会引发控制台错误,并且会呈现一个简单的 html 表格,而没有分页、搜索和排序功能
  • @SamzSakerz 我已经直接用cdn链接导入Datatable了,想知道会使用js的rowspan的解决方案。我是 js 新手,需要帮助解决这个问题。请建议是否应该对帖子进行任何编辑。谢谢

标签: javascript jquery html datatables handlebars.js


【解决方案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 外部库并在数据表配置中应用'rowsGroup': [index_of_column]。 希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 1970-01-01
    • 2011-01-02
    • 2012-10-19
    相关资源
    最近更新 更多