eca0b3b3d1a44244ffd501787a9163c718cbe5c1
FAQ/passing-alternate-filter-values-with-a-table-or-view.md
| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | +#Substituting filter values for other values when using a table or view |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##Question |
|
| 6 | + |
|
| 7 | +When I filter a report built on a table or view, I want to pass a different value than what is displayed. How can I accomplish this in Izenda? |
|
| 8 | + |
|
| 9 | +##Answer |
|
| 10 | + |
|
| 11 | +Please refer to the included sample code. In this code, we override PostProcessEqualsSelectList in order to populate a filter with a set of paired values. Values from the CompanyName column will be placed in the filter dropdown which users can select, but the corresponding value from CompanyID will be placed in the where clause of the query. |
|
| 12 | + |
|
| 13 | +```csharp |
|
| 14 | +public override void PostProcessEqualsSelectList(Column column, List<string> labels, List<string> values) |
|
| 15 | +{ |
|
| 16 | + if (column.Name == "CustomerID") |
|
| 17 | + { |
|
| 18 | + var sql = string.Format("SELECT [CustomerID] AS \"Value\", [CompanyName] AS \"Label\" FROM [Customers] WHERE [CustomerID] IN ({0}) ORDER BY [CompanyName]", string.Join(",", values.Where(v => v != "...").Select(v => "'" + v + "'"))); |
|
| 19 | + var ds = AdHocContext.Driver.ExecuteDataSet(sql); |
|
| 20 | + if (ds != null && ds.Tables.Count > 0) |
|
| 21 | + { |
|
| 22 | + var table = ds.Tables[0]; |
|
| 23 | + values.Clear(); |
|
| 24 | + labels.Clear(); |
|
| 25 | + values.Add("..."); |
|
| 26 | + labels.Add("..."); |
|
| 27 | + foreach (DataRow row in table.Rows) |
|
| 28 | + { |
|
| 29 | + values.Add(row["Value"].ToString()); |
|
| 30 | + labels.Add(row["Label"].ToString()); |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | +} |
|
| 35 | +``` |
|
| ... | ... | \ No newline at end of file |