ced8b2e51785afafd915cbf5b6009c2deb223ac2
FAQ/Questions/How-To-Preset-Values-In-Filter.md
| ... | ... | @@ -0,0 +1,45 @@ |
| 1 | +#How to preset values in filter |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##Question |
|
| 6 | + |
|
| 7 | +How can I preset date values in time period filter? |
|
| 8 | + |
|
| 9 | +##Answer |
|
| 10 | + |
|
| 11 | +You can use hidden filter to make reports pre-filtered whenever they are opened so that viewers only see the filtered results. However, hidden filter is not available when the filter operator is something else other than 'Equals'. Still, you can preset values in filter using PreExecuteReportSet method as below |
|
| 12 | + |
|
| 13 | + |
|
| 14 | +###Example: Presetting a time period (From a year ago to Today) |
|
| 15 | + |
|
| 16 | +```csharp |
|
| 17 | + public override void PreExecuteReportSet(ReportSet reportSet) |
|
| 18 | + { |
|
| 19 | + base.PreExecuteReportSet(reportSet); |
|
| 20 | + |
|
| 21 | + // if (reportSet.ReportName != "MyReport" || reportSet.ReportName != "MyReport2") // You can choose to which report this overriding to be applied |
|
| 22 | +// return; |
|
| 23 | + |
|
| 24 | + foreach (Izenda.AdHoc.Filter filter in reportSet.Filters) { |
|
| 25 | + |
|
| 26 | + if (filter.Operator == OperatorTypes.BetweenTwoDates) { // can choose filter as well based on its operator |
|
| 27 | + |
|
| 28 | + if (filter.dbColumn.Name.Equals("OrderDate")) { // To be applied to "OrderDate" filter |
|
| 29 | + |
|
| 30 | + DateTime baseDate = DateTime.Today; |
|
| 31 | + |
|
| 32 | + filter.Values.SetValue(baseDate.AddYears(-1), 0); //the'Between' operator takes two parameters. the first one's indexed as 0. '-1' for a year ago |
|
| 33 | + |
|
| 34 | + filter.Values.SetValue(DateTime.Today, 1); |
|
| 35 | + |
|
| 36 | +// reportSet.Filters[count].Values.SetValue("01/01/2010", 1); |
|
| 37 | +// reportSet.Filters[count].Values.SetValue("01/01/2016", 1); // the date value could be a specific date |
|
| 38 | + |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | +``` |
|
| 45 | + |