在数据表中使用行跨度
Using row span in Data Tables
{% 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 请求后动态呈现一个 table 并且想按配置名称对行进行分组。当我在 Data Table 中使用 rowspan 时,只呈现简单的 table 并且出现控制台错误:
jquery.dataTables.min.js:24 未捕获类型错误:无法设置未定义的 属性 '_DT_CellIndex'
我正在使用 handlebars.js 填充 Table-Template
数据表:
https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js">
https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js">
有没有办法以这种格式生成 table,同时保持数据table 的特性。
$(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]
。
希望对你有帮助。
{% 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 请求后动态呈现一个 table 并且想按配置名称对行进行分组。当我在 Data Table 中使用 rowspan 时,只呈现简单的 table 并且出现控制台错误:
jquery.dataTables.min.js:24 未捕获类型错误:无法设置未定义的 属性 '_DT_CellIndex'
我正在使用 handlebars.js 填充 Table-Template
数据表: https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"> https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js">
有没有办法以这种格式生成 table,同时保持数据table 的特性。
$(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]
。
希望对你有帮助。