Skip to content

Commit 343e6f8

Browse files
committed
Improve dropdown behaviour and include deselect all button. Bump v0.2.3.
1 parent 8f756ab commit 343e6f8

File tree

8 files changed

+151
-69
lines changed

8 files changed

+151
-69
lines changed

assets/reportviewer-net.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,26 @@
6767
margin-left: 0.25rem;
6868
}
6969

70-
.reportparam-list-selectall {
70+
.reportparam-list-selectall,
71+
.reportparam-list-deselectall {
7172
background-color: transparent;
7273
border: none;
7374
padding-left: 0;
7475
color: #007bff;
7576
}
7677

77-
.reportparam-list-selectall:hover {
78+
.reportparam-list-selectall:hover,
79+
.reportparam-list-deselectall:hover {
7880
color: #0056b3;
7981
text-decoration: underline;
8082
background-color: transparent;
8183
border-color: transparent;
8284
}
8385

86+
.reportparam-list-deselectall {
87+
margin-right: 5px;
88+
}
89+
8490
.report-viewer {
8591
position: relative;
8692
}

assets/reportviewer-net.js

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
return dtoArr;
6666
}
6767

68-
self.selectCheckbox = function (element, selectAll) {
68+
self.selectCheckbox = function (element, selectAll, deselectAll) {
6969
var id = $(element).attr('id');
7070
var list = id.indexOf('-') > -1;
7171

@@ -84,12 +84,15 @@
8484
if (selectAll) {
8585
$(element).prop('checked', true);
8686
}
87+
else if (deselectAll) {
88+
$(element).prop('checked', false);
89+
}
8790
else {
8891
$(element).prop('checked', checked);
8992
}
9093
}
91-
92-
self.postReportParameters = function () {
94+
95+
self.postReportParameters = function (callback) {
9396
var dtoArr = constructReportParameters();
9497
var dto = {
9598
Parameters: dtoArr
@@ -105,51 +108,48 @@
105108

106109
let paramLists = $('.report-viewer .reportparam-list');
107110

108-
$('.report-viewer .reportparameters-container').on("click", function (e) {
109-
let load = false;
111+
if (callback) {
112+
callback();
113+
}
110114

115+
$('.report-viewer .reportparameters-container').on("click", function (e) {
111116
if (e.target !== e.currentTarget) {
112117
return;
113118
}
114119

115-
$.each(paramLists, function (idx, list) {
116-
let dropdownContainers = $(list).find('.reportparam-list-dropdown[class*="open"]');
117-
118-
$.each(dropdownContainers, function (idx, ele) {
119-
if (!list.contains(e.target)) {
120-
$(ele).removeClass('open');
121-
$(ele).css('display', 'none');
122-
load = true;
123-
}
124-
});
125-
});
126-
127-
if (load || paramLists.length === 0) {
128-
self.postReportParameters();
129-
}
120+
self.processUserAction();
130121
});
131122

132-
$('.report-viewer .reportparam-list-select .over-select').on("click", function () {
133-
let dropdownContainer = $(this).closest('.reportparam-list').find('.reportparam-list-dropdown');
123+
$('.report-viewer .reportparam-list-select .over-select').on("click", function (e) {
124+
e.preventDefault();
125+
126+
self.processUserAction(function () {
127+
let currentTarget = e.currentTarget;
128+
let dropdownContainer = $(currentTarget).closest('.reportparam-list').find('.reportparam-list-dropdown');
129+
let dropdownOptions = $(dropdownContainer).find('.custom-checkbox');
134130

135-
if (!$(dropdownContainer).is(':empty')) {
136-
if ($(dropdownContainer).css('display') === 'none') {
131+
if ($(dropdownContainer).css('display') === 'none' && dropdownOptions.length > 0) {
137132
$(dropdownContainer).addClass('open');
138133
$(dropdownContainer).css('display', 'block');
139134
}
140-
else {
141-
$(dropdownContainer).removeClass('open');
142-
$(dropdownContainer).css('display', 'none');
143-
}
144-
}
135+
});
145136
});
146137

147138
$('.report-viewer .reportparam-list-dropdown .reportparam-list-selectall').on("click", function () {
148139
let dropdownContainer = $(this).closest('.reportparam-list').find('.reportparam-list-dropdown');
149140
let checkboxes = $(dropdownContainer).find('input[type="checkbox"]');
150141

151142
$.each(checkboxes, function (idx, ele) {
152-
self.selectCheckbox($(ele), true);
143+
self.selectCheckbox($(ele), true, false);
144+
});
145+
});
146+
147+
$('.report-viewer .reportparam-list-dropdown .reportparam-list-deselectall').on("click", function () {
148+
let dropdownContainer = $(this).closest('.reportparam-list').find('.reportparam-list-dropdown');
149+
let checkboxes = $(dropdownContainer).find('input[type="checkbox"]');
150+
151+
$.each(checkboxes, function (idx, ele) {
152+
self.selectCheckbox($(ele), false, true);
153153
});
154154
});
155155

@@ -159,8 +159,12 @@
159159
}
160160
});
161161

162+
$('.report-viewer input[type="text"]').on("focus", function (event) {
163+
self.processUserAction();
164+
});
165+
162166
$('.report-viewer input[type="checkbox"]').on("change", function (event) {
163-
self.selectCheckbox($(this), false);
167+
self.selectCheckbox($(this), false, false);
164168
});
165169

166170
$('.report-viewer #RunReportBtn').on('click', function () {
@@ -171,6 +175,27 @@
171175
});
172176
}
173177

178+
self.processUserAction = function (callback) {
179+
let paramLists = $('.report-viewer .reportparam-list');
180+
let load = false;
181+
182+
$.each(paramLists, function (idx, list) {
183+
let dropdownContainers = $(list).find('.reportparam-list-dropdown[class*="open"]');
184+
185+
$.each(dropdownContainers, function (idx, ele) {
186+
$(ele).removeClass('open');
187+
$(ele).css('display', 'none');
188+
load = true;
189+
});
190+
});
191+
192+
if (load || paramLists.length === 0) {
193+
self.postReportParameters(callback);
194+
} else if (callback) {
195+
callback();
196+
}
197+
};
198+
174199
self.renderReport = function() {
175200
var dtoArr = constructReportParameters();
176201
var dto = {

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ The library works by parsing RDL files which you must register, along with DataS
1414

1515
ReportViewer.NET is currently designed to target .NET 8.
1616

17+
## Dependencies
18+
19+
1. jQuery for the client side script bundled with this library. The script is not currently available as a module for importing, but I will eventually do this.
20+
1721
## How to use
1822

1923
1. Include the provided CSS in `assets/reportviewer.net.css` in your project.

src/ReportViewer.NET.Web/wwwroot/css/site.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,26 @@
6767
margin-left: 0.25rem;
6868
}
6969

70-
.reportparam-list-selectall {
70+
.reportparam-list-selectall,
71+
.reportparam-list-deselectall {
7172
background-color: transparent;
7273
border: none;
7374
padding-left: 0;
7475
color: #007bff;
7576
}
7677

77-
.reportparam-list-selectall:hover {
78+
.reportparam-list-selectall:hover,
79+
.reportparam-list-deselectall:hover {
7880
color: #0056b3;
7981
text-decoration: underline;
8082
background-color: transparent;
8183
border-color: transparent;
8284
}
8385

86+
.reportparam-list-deselectall {
87+
margin-right: 5px;
88+
}
89+
8490
.report-viewer {
8591
position: relative;
8692
}

src/ReportViewer.NET.Web/wwwroot/js/site.js

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
return dtoArr;
6666
}
6767

68-
self.selectCheckbox = function (element, selectAll) {
68+
self.selectCheckbox = function (element, selectAll, deselectAll) {
6969
var id = $(element).attr('id');
7070
var list = id.indexOf('-') > -1;
7171

@@ -84,12 +84,15 @@
8484
if (selectAll) {
8585
$(element).prop('checked', true);
8686
}
87+
else if (deselectAll) {
88+
$(element).prop('checked', false);
89+
}
8790
else {
8891
$(element).prop('checked', checked);
8992
}
9093
}
91-
92-
self.postReportParameters = function () {
94+
95+
self.postReportParameters = function (callback) {
9396
var dtoArr = constructReportParameters();
9497
var dto = {
9598
Parameters: dtoArr
@@ -105,51 +108,48 @@
105108

106109
let paramLists = $('.report-viewer .reportparam-list');
107110

108-
$('.report-viewer .reportparameters-container').on("click", function (e) {
109-
let load = false;
111+
if (callback) {
112+
callback();
113+
}
110114

115+
$('.report-viewer .reportparameters-container').on("click", function (e) {
111116
if (e.target !== e.currentTarget) {
112117
return;
113118
}
114119

115-
$.each(paramLists, function (idx, list) {
116-
let dropdownContainers = $(list).find('.reportparam-list-dropdown[class*="open"]');
117-
118-
$.each(dropdownContainers, function (idx, ele) {
119-
if (!list.contains(e.target)) {
120-
$(ele).removeClass('open');
121-
$(ele).css('display', 'none');
122-
load = true;
123-
}
124-
});
125-
});
126-
127-
if (load || paramLists.length === 0) {
128-
self.postReportParameters();
129-
}
120+
self.processUserAction();
130121
});
131122

132-
$('.report-viewer .reportparam-list-select .over-select').on("click", function () {
133-
let dropdownContainer = $(this).closest('.reportparam-list').find('.reportparam-list-dropdown');
123+
$('.report-viewer .reportparam-list-select .over-select').on("click", function (e) {
124+
e.preventDefault();
125+
126+
self.processUserAction(function () {
127+
let currentTarget = e.currentTarget;
128+
let dropdownContainer = $(currentTarget).closest('.reportparam-list').find('.reportparam-list-dropdown');
129+
let dropdownOptions = $(dropdownContainer).find('.custom-checkbox');
134130

135-
if (!$(dropdownContainer).is(':empty')) {
136-
if ($(dropdownContainer).css('display') === 'none') {
131+
if ($(dropdownContainer).css('display') === 'none' && dropdownOptions.length > 0) {
137132
$(dropdownContainer).addClass('open');
138133
$(dropdownContainer).css('display', 'block');
139134
}
140-
else {
141-
$(dropdownContainer).removeClass('open');
142-
$(dropdownContainer).css('display', 'none');
143-
}
144-
}
135+
});
145136
});
146137

147138
$('.report-viewer .reportparam-list-dropdown .reportparam-list-selectall').on("click", function () {
148139
let dropdownContainer = $(this).closest('.reportparam-list').find('.reportparam-list-dropdown');
149140
let checkboxes = $(dropdownContainer).find('input[type="checkbox"]');
150141

151142
$.each(checkboxes, function (idx, ele) {
152-
self.selectCheckbox($(ele), true);
143+
self.selectCheckbox($(ele), true, false);
144+
});
145+
});
146+
147+
$('.report-viewer .reportparam-list-dropdown .reportparam-list-deselectall').on("click", function () {
148+
let dropdownContainer = $(this).closest('.reportparam-list').find('.reportparam-list-dropdown');
149+
let checkboxes = $(dropdownContainer).find('input[type="checkbox"]');
150+
151+
$.each(checkboxes, function (idx, ele) {
152+
self.selectCheckbox($(ele), false, true);
153153
});
154154
});
155155

@@ -159,8 +159,12 @@
159159
}
160160
});
161161

162+
$('.report-viewer input[type="text"]').on("focus", function (event) {
163+
self.processUserAction();
164+
});
165+
162166
$('.report-viewer input[type="checkbox"]').on("change", function (event) {
163-
self.selectCheckbox($(this), false);
167+
self.selectCheckbox($(this), false, false);
164168
});
165169

166170
$('.report-viewer #RunReportBtn').on('click', function () {
@@ -171,6 +175,27 @@
171175
});
172176
}
173177

178+
self.processUserAction = function (callback) {
179+
let paramLists = $('.report-viewer .reportparam-list');
180+
let load = false;
181+
182+
$.each(paramLists, function (idx, list) {
183+
let dropdownContainers = $(list).find('.reportparam-list-dropdown[class*="open"]');
184+
185+
$.each(dropdownContainers, function (idx, ele) {
186+
$(ele).removeClass('open');
187+
$(ele).css('display', 'none');
188+
load = true;
189+
});
190+
});
191+
192+
if (load || paramLists.length === 0) {
193+
self.postReportParameters(callback);
194+
} else if (callback) {
195+
callback();
196+
}
197+
};
198+
174199
self.renderReport = function() {
175200
var dtoArr = constructReportParameters();
176201
var dto = {

src/ReportViewer.NET/DataObjects/ReportParameter.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ public string Build(ReportRDL report, ReportParameter userProvidedParameter)
4848
var elementId = $"{this.Name}-{idx}";
4949

5050
dropdownContainer.AppendLine(@"
51-
<button id=""" + elementId + @""" class=""reportparam-list-selectall"">Select all</button>
51+
<button id=""" + elementId + @""" class=""reportparam-list-selectall"">Select all</button>
52+
");
53+
54+
idx++;
55+
56+
elementId = $"{this.Name}-{idx}";
57+
58+
dropdownContainer.AppendLine(@"
59+
<button id=""" + elementId + @""" class=""reportparam-list-deselectall"">Deselect all</button>
5260
");
5361

5462
idx++;
@@ -127,6 +135,14 @@ public string Build(ReportRDL report, ReportParameter userProvidedParameter)
127135
");
128136

129137
idx++;
138+
139+
elementId = $"{this.Name}-{idx}";
140+
141+
dropdownContainer.AppendLine(@"
142+
<button id=""" + elementId + @""" class=""reportparam-list-deselectall"">Deselect all</button>
143+
");
144+
145+
idx++;
130146
}
131147

132148
foreach (var pv in ParameterValues)

src/ReportViewer.NET/LayoutProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ private async Task<IEnumerable<IDictionary<string, object>>> RunDataSetQuery(Rep
359359
(queryParam.Value.StartsWith("=Parameters!") && p.Name == this.ExtractParameterNameFromDataSetQueryParameter(queryParam.Value))
360360
);
361361

362-
if (invalidParameter || (!nullableOrDefault && string.IsNullOrEmpty(userParam.Value) && !userParam.Values.Any()))
362+
if (invalidParameter || (!nullableOrDefault && string.IsNullOrEmpty(userParam.Value) && (userParam.Values == null || !userParam.Values.Any())))
363363
{
364364
break;
365365
}

0 commit comments

Comments
 (0)