gpt4 book ai didi

javascript - 如何自定义数据表中的表?

转载 作者:行者123 更新时间:2023-12-03 07:11:23 27 4
gpt4 key购买 nike

我搜索了很多链接,但没有找到任何自定义表格的解决方案。任何小建议都会有所帮助。

通常我们得到的数据表是这样的结构:


|  col1          | col2           | col3           |
|---------------------------------------------------
| col1 row1 | col2 row1 | col3 row1 |
|---------------------------------------------------
| col1 row2 | col2 row2 | col3 row2 |
|---------------------------------------------------

现在我要数据表中的结构如


|  col1          | col2           | col3           |
|---------------------------------------------------
| | col2 row11 | col3 row11 |
| row1 -----------------------------------
| | col2 row2 1 | col3 row12 |
|---------------------------------------------------

最佳答案

试试这个例子,

$(document).ready( function () {
var data = [
['subgroupN', 'Group1', 'sub-subgroupN', 'ElementN', '2Element N'],
['subgroup1', 'Group2', 'sub-subgroup1', 'Element1', '2Element 1'],
['subgroup2', 'Group2', 'sub-subgroup1', 'Element1', '2Element 1'],
['subgroup2', 'Group2', 'sub-subgroup1', 'Element2', '2Element 2'],
['subgroup2', 'Group2', 'sub-subgroup2', 'Element3', '2Element 2'],
['subgroup2', 'Group2', 'sub-subgroup2', 'Element4', '2Element 4'],
['subgroup2', 'Group2', 'sub-subgroup2', 'Element2', '2Element 2'],
['subgroup3', 'Group1', 'sub-subgroup1', 'Element1', '2Element 1'],
['subgroup3', 'Group1', 'sub-subgroup1', 'Element1', '2Element 1'],
['subgroup2', 'Group2', 'sub-subgroup2', 'Element1', '2Element 1'],
['subgroup4', 'Group2', 'sub-subgroup2', 'Element1', '2Element 1'],
['subgroup4', 'Group2', 'sub-subgroup3', 'Element10', '2Element 17'],
['subgroup4', 'Group2', 'sub-subgroup3', 'Element231', '2Element 211'],

];
var table = $('#example').DataTable({
columns: [
{
title: 'First group',
},
{
name: 'second',
title: 'Second group [order first]',
},
{
title: 'Third group',
},
{
title: 'Forth ungrouped',
},
{
title: 'Fifth ungrouped',
},
],
data: data,
rowsGroup: [// Always the array (!) of the column-selectors in specified order to which rows grouping is applied
// (column-selector could be any of specified in https://datatables.net/reference/type/column-selector)
'second:name',
0,
2
],
pageLength: '20',
});
} );
body {
font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
color: #333;
background-color: #fff;
}


div.container {
min-width: 980px;
margin: 0 auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>

<link href="//datatables.net/download/build/nightly/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="//datatables.net/download/build/nightly/jquery.dataTables.js"></script>
<script src="//cdn.rawgit.com/ashl1/datatables-rowsgroup/v1.0.0/dataTables.rowsGroup.js"></script>

<meta charset=utf-8 />
<title>DataTables - JS Bin</title>
</head>
<body>
<div class="container">
<table id="example" class="display" width="100%">
</table>
</div>
</body>
</html>

希望对您有所帮助。

更多示例访问,

How to add Rowspan in JQuery datatables

关于javascript - 如何自定义数据表中的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50441709/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com