Skip to content

Commit aec3cda

Browse files
committed
Support for expand all nodes or expand just one
node
1 parent 3b06ca8 commit aec3cda

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎src/extensions/group-by/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ You must include the bootstrap-table-group-by.css file in order to get the appro
3333
### groupByInitExpanded
3434

3535
* type: Boolean
36-
* description: Set to True to expand the first node of the table.
37-
* default: `false`
36+
* description: You can use the node number (parent row index) or you can use the `all` option in order to expand all nodes of the table.
37+
* default: `undefined`
3838

3939
## Methods
4040

‎src/extensions/group-by/bootstrap-table-group-by.js‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
obj = {},
1515
parentId = undefined;
1616

17+
var getParentRowId = function (that, id) {
18+
var parentRows = that.$body.find('tr').not('[' + 'data-tt-parent-id]');
19+
20+
for (var i = 0; i < parentRows.length; i++) {
21+
if (i === id) {
22+
return $(parentRows[i]).attr('data-tt-id');
23+
}
24+
}
25+
26+
return undefined;
27+
};
28+
1729
var sumData = function (that, data) {
1830
var sumRow = {};
1931
$.each(data, function (i, row) {
@@ -109,7 +121,7 @@
109121
groupBy: false,
110122
groupByField: '',
111123
groupBySumGroup: false,
112-
groupByInitExpanded: false,
124+
groupByInitExpanded: undefined, //node, 'all'
113125
//internal variables
114126
loaded: false,
115127
originalData: undefined
@@ -156,8 +168,12 @@
156168
}
157169
}, true);
158170

159-
if (that.options.groupByInitExpanded) {
160-
that.expandNode('0');
171+
if (that.options.groupByInitExpanded !== undefined) {
172+
if (typeof that.options.groupByInitExpanded === 'number') {
173+
that.expandNode(that.options.groupByInitExpanded);
174+
} else if (that.options.groupByInitExpanded.toLowerCase() === 'all') {
175+
that.expandAll();
176+
}
161177
}
162178
});
163179
}
@@ -184,6 +200,9 @@
184200
};
185201

186202
BootstrapTable.prototype.expandNode = function (id) {
187-
this.$el.treetable('expandNode', id);
203+
id = getParentRowId(this, id);
204+
if (id !== undefined) {
205+
this.$el.treetable('expandNode', id);
206+
}
188207
}
189208
}(jQuery);

0 commit comments

Comments
 (0)