4df64a3a7e03bf458bd141f3a28a50c52b9a3ff3
Guides/Set-Default-Filter-Values.md
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +#Set Default Filter Values |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##Purpose |
|
| 6 | + |
|
| 7 | +There are multiple scenarios where having the filter values set as soon as a report loads can be beneficial. The following examples will show how it is coded for dashboards. |
|
| 8 | +<!-- |
|
| 9 | +##Reports |
|
| 10 | +--> |
|
| 11 | + |
|
| 12 | +##Dashboards |
|
| 13 | + |
|
| 14 | +Dashboards themselves do not have filters and therefore reference the filters of the reports it is composed of. |
|
| 15 | +This method can be used for stored procedures as well as tables and views. |
|
| 16 | + |
|
| 17 | +```c# |
|
| 18 | +public override ReportSet LoadReportSet(ReportInfo reportInfo, DatabaseSchema schema) { |
|
| 19 | + ReportSet reportSet = base.LoadReportSet(reportInfo, schema); |
|
| 20 | + if (reportInfo.Name == "Dashboard Proc Test") { |
|
| 21 | + foreach (string report in reportSet.Reports) { |
|
| 22 | + reportSet.Reports[report].Filters[0].Value = DateTime.ParseExact("01/01/2010", "mm/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture); |
|
| 23 | + reportSet.Reports[report].Filters[1].Value = DateTime.ParseExact("01/01/2014", "mm/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture); |
|
| 24 | + } |
|
| 25 | + } |
|
| 26 | + return reportSet; |
|
| 27 | + } |
|
| 28 | +``` |
|
| 29 | + |
|
| 30 | +#Additional Notes |
|
| 31 | + |
|
| 32 | +The between calendar uses two values. To set each of its dates, you would use the following. |
|
| 33 | + |
|
| 34 | +```c# |
|
| 35 | +reportSet.Reports[report].Filters[0].Values.SetValue(DateTime.ParseExact("01/01/2010", "mm/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture),0); |
|
| 36 | +reportSet.Reports[report].Filters[0].Values.SetValue(DateTime.ParseExact("01/01/2014", "mm/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture),1); |
|
| 37 | +``` |
|
| ... | ... | \ No newline at end of file |