Skip to content

Commit 6c7a917

Browse files
author
Allan Jardine
committed
New: Multi-level nesting. The -init rowGroup.dataSrc option can now be used to nest multiple levels of data by providing this option as an array of values. A new example shows this ability.
New: Classes applied by RowGroup are prefixed by `dtrg-` (DataTables RowGroup) to match the similar styling used by other DataTables extensions.
1 parent 9790bb7 commit 6c7a917

File tree

5 files changed

+204
-163
lines changed

5 files changed

+204
-163
lines changed

css/rowGroup.dataTables.scss

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11

22

33
$table-rowgroup-background: #e0e0e0 !default;
4+
$table-rowgroup-background-level-1: #f0f0f0 !default;
5+
$table-rowgroup-background-level-2: #f3f3f3 !default;
46

5-
table.dataTable tr.group td {
6-
font-weight: bold;
7+
table.dataTable tr.dtrg-group td {
78
background-color: $table-rowgroup-background;
89
}
910

11+
table.dataTable tr.dtrg-group.dtrg-level-0 td {
12+
font-weight: bold;
13+
}
14+
15+
table.dataTable tr.dtrg-group.dtrg-level-1 td,
16+
table.dataTable tr.dtrg-group.dtrg-level-2 td {
17+
background-color: $table-rowgroup-background-level-1;
18+
padding-top: 0.25em;
19+
padding-bottom: 0.25em;
20+
padding-left: 2em;
21+
font-size: 0.9em;
22+
}
23+
24+
table.dataTable tr.dtrg-group.dtrg-level-2 td {
25+
background-color: $table-rowgroup-background-level-2;
26+
}
27+

docs/api/rowGroup().dataSrc().xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
<description>
1111
Get the property currently being used as the grouping data source.
1212
</description>
13-
<returns type="number|string">Data source property</returns>
13+
<returns type="number|string|array">Data source property</returns>
1414
</type>
1515

1616
<type type="function">
1717
<name>rowGroup().dataSrc()</name>
1818
<signature>rowGroup().dataSrc( prop )</signature>
1919
<description>
2020
Set the property to be used as the grouping data source.
21+
22+
As of RowGroup 1.1.0 it is possible to set this value to be an array, allowing multiple levels of row grouping.
2123
</description>
22-
<parameter name="prop" type="number|string">
24+
<parameter name="prop" type="number|string|array">
2325

2426
</parameter>
2527
<returns type="DataTables.Api">DataTables API instance</returns>

docs/option/rowGroup.dataSrc.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
</description>
1111
</type>
1212

13+
<type type="array" since="1.1.0">
14+
<description>
15+
As of RowGroup 1.1.0 it is possible to nest multiple levels of data by providing this parameter as an array of values. The values can be numbers or strings as defined above. The top level of nesting is array index 0, and progressively gets deeper with the array indexes.
16+
</description>
17+
</type>
18+
1319
<default value="0"/>
1420

1521
<description>
@@ -30,6 +36,19 @@ $('#myTable').DataTable( {
3036
}
3137
} );
3238
39+
]]></example>
40+
41+
<example title="Nested data"><![CDATA[
42+
43+
$('#myTable').DataTable( {
44+
rowGroup: {
45+
dataSrc: [
46+
'group',
47+
'date'
48+
]
49+
}
50+
} );
51+
3352
]]></example>
3453

3554
</dt-option>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<dt-example table-type="html" order="7">
3+
4+
<css lib="datatables rowgroup">
5+
6+
tr.odd td:first-child,
7+
tr.even td:first-child {
8+
padding-left: 4em;
9+
}
10+
11+
</css>
12+
<js lib="jquery datatables rowgroup">
13+
<![CDATA[
14+
15+
$(document).ready(function() {
16+
$('#example').DataTable( {
17+
order: [[2, 'asc'], [1, 'asc']],
18+
rowGroup: {
19+
dataSrc: [ 2, 1 ]
20+
},
21+
columnDefs: [ {
22+
targets: [ 1, 2 ],
23+
visible: false
24+
} ]
25+
} );
26+
} );
27+
28+
]]>
29+
</js>
30+
31+
<title lib="RowGroup">Multi-level grouping</title>
32+
33+
<info><![CDATA[
34+
35+
RowGroup provides the ability to group data a multiple levels. This example shows the `-init rowGroup.dataSrc` option being used as an array to specify the _Office_ as the top level group and _Position_ as the second level.
36+
37+
A little CSS is used to indent the first column to reflect the visual nesting of data (click the "CSS" tab below to view).
38+
39+
]]></info>
40+
41+
</dt-example>
42+

0 commit comments

Comments
 (0)