I have filters set up that will hide certain rows of my bootstrap-table. I have also implemented the “expandAllRows” method to display all detail-views; however, this method will expand ALL rows including those that are hidden by my filters.
How would I modify bootstrap-table.min.js in order to only show the detail-views of the rows that are visible?
I believe I need to modify the line from bootstrap-table.min.js but not sure how:
JavaScript
x
2
1
key:"expandAllRows",value:function(){for(var t=this.$body.find("> tr[data-index][data-has-detail-view]"),e=0;e<t.length;e++)this.expandRow(i.default(t[e[).data("index"))} {
2
I am using the bootstrap-table buttons method to add the custom buttons for expanding and collapsing the rows. See below:
JavaScript
1
30
30
1
function buttons() {
2
var $table = $('#table')
3
var $expand = $('#expand')
4
var $collapse = $('#collapse')
5
6
return {
7
btnExpand: {
8
text: 'Expand All Rows',
9
icon: 'fas fa-angle-double-down',
10
event: function() {
11
$table.bootstrapTable('expandAllRows')
12
},
13
attributes: {
14
title: 'Expand all rows'
15
}
16
},
17
btnCollapse: {
18
text: 'Collapse All Rows',
19
icon: 'fas fa-angle-double-up',
20
event: function() {
21
$table.bootstrapTable('collapseAllRows')
22
},
23
attributes: {
24
title: 'Collapse all rows'
25
}
26
}
27
}
28
}
29
30
Advertisement
Answer
Rather than modify bootstraps’ functions, maybe you could just circumvent them by renaming the attribute when you filter them. Something like this
JavaScript
1
24
24
1
function filter(keyword) {
2
// your current filter logic, which hides the rows that don't match
3
// in this example, you have hidden them with the class 'hidden-row'
4
let hiddenRows=$("tr.hidden-row[data-has-detail-view='true']");
5
hiddenRows.each( function() {
6
$(this).attr({
7
'data-has-detail-view-hidden': 'true'
8
})
9
.removeAttr('data-has-detail-view');
10
})
11
}
12
13
function clearFilters() {
14
// your logic, then
15
let hiddenRows=$("tr.hidden-row[data-has-detail-view-hidden='true']");
16
hiddenRows.each( function() {
17
$(this).attr({
18
'data-has-detail-view': 'true'
19
})
20
.removeAttr('data-has-detail-view-hidden')
21
.removeClass('hidden-row');
22
})
23
}
24