cd79d6753ac9514134fdb57e556f26b397879885
FAQ/GetPossibleValuesAsTree.md
| ... | ... | @@ -0,0 +1,92 @@ |
| 1 | +#GetPossibleValuesAsTree |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##About |
|
| 6 | + |
|
| 7 | +The GetPossibleValuesAsTree method is an overridable method in the [[AdHocConfig|/FAQ/AdHocConfig]] class that can change the behavior of the Equals (Tree) filter operator. This option is normally hidden from appearing on the list until it is overridden in your CustomAdHocConfig. The [[Equals (Tree)|http://wiki.izenda.us/Guides/ReportDesign/5.0-Filters-tab#5.3-Operator-Categories]] operator will allow you to select elements based on a hierarchy of values starting with "All", which is the root option. Values can be expanded out from the root option and any number may be selected. |
|
| 8 | + |
|
| 9 | +##C♯ Method |
|
| 10 | + |
|
| 11 | +In the following example, we will be using the Northwind example database to construct the Equals (Tree) list for the columns ShipCity and ProductName. You may use this snippet to construct an Equals (Tree) list that works for your particular organization. |
|
| 12 | + |
|
| 13 | +```csharp |
|
| 14 | +public override System.Collections.Generic.IList<ValueTreeNode> GetPossibleValuesAsTree(string fullColumnName, |
|
| 15 | + int maxRowCount, ReportSet rs) { |
|
| 16 | + if (string.IsNullOrEmpty(fullColumnName) || fullColumnName == "...") |
|
| 17 | + return new System.Collections.Generic.List<ValueTreeNode>(); |
|
| 18 | + |
|
| 19 | + if (fullColumnName == "[dbo].[Orders].[ShipCity]" || fullColumnName == "[dbo].[Invoices].[ShipCity]") { |
|
| 20 | + System.Collections.Generic.IList<ValueTreeNode> result = new System.Collections.Generic.List<ValueTreeNode>(); |
|
| 21 | + ValueTreeNode all = new ValueTreeNode("All"); |
|
| 22 | + ValueTreeNode none = new ValueTreeNode("(none)"); |
|
| 23 | + result.Add(all); |
|
| 24 | + result.Add(none); |
|
| 25 | + all.Nodes = new System.Collections.Generic.List<ValueTreeNode>(); |
|
| 26 | + |
|
| 27 | + string tableName = "[dbo].[Orders]"; |
|
| 28 | + if (fullColumnName == "[dbo].[Invoices].[ShipCity]") |
|
| 29 | + tableName = "[dbo].[Invoices]"; |
|
| 30 | + System.Data.DataSet ds = |
|
| 31 | + AdHocContext.Driver.ExecuteDataSet( |
|
| 32 | + "SELECT DISTINCT [ShipCountry], [ShipRegion], [ShipCity] from " + tableName + |
|
| 33 | + " order by [ShipCountry], [ShipRegion], [ShipCity]", false); |
|
| 34 | + System.Data.DataTable table = ds.Tables[0]; |
|
| 35 | + |
|
| 36 | + ValueTreeNode shipCountry = null; |
|
| 37 | + ValueTreeNode shipRegion = null; |
|
| 38 | + foreach (System.Data.DataRow row in table.Rows) { |
|
| 39 | + string country = row[0].ToString(); |
|
| 40 | + if (shipCountry == null || shipCountry.Text != country) { |
|
| 41 | + shipCountry = new ValueTreeNode(country); |
|
| 42 | + all.Nodes.Add(shipCountry); |
|
| 43 | + shipCountry.Nodes = new System.Collections.Generic.List<ValueTreeNode>(); |
|
| 44 | + shipRegion = null; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + string region = row[1].ToString(); |
|
| 48 | + if (string.IsNullOrEmpty(region)) { |
|
| 49 | + shipRegion = shipCountry; |
|
| 50 | + } |
|
| 51 | + else { |
|
| 52 | + if (shipRegion == null || shipRegion.Text != region) { |
|
| 53 | + shipRegion = new ValueTreeNode(region); |
|
| 54 | + shipCountry.Nodes.Add(shipRegion); |
|
| 55 | + shipRegion.Nodes = new System.Collections.Generic.List<ValueTreeNode>(); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + shipRegion.Nodes.Add(new ValueTreeNode(row[2].ToString())); |
|
| 59 | + } |
|
| 60 | + return result; |
|
| 61 | + } |
|
| 62 | + else if (fullColumnName == "[dbo].[Products].[ProductName]") { |
|
| 63 | + System.Collections.Generic.IList<ValueTreeNode> result = new System.Collections.Generic.List<ValueTreeNode>(); |
|
| 64 | + ValueTreeNode all = new ValueTreeNode("All"); |
|
| 65 | + ValueTreeNode none = new ValueTreeNode("(none)"); |
|
| 66 | + result.Add(all); |
|
| 67 | + result.Add(none); |
|
| 68 | + all.Nodes = new System.Collections.Generic.List<ValueTreeNode>(); |
|
| 69 | + |
|
| 70 | + System.Data.DataSet ds = |
|
| 71 | + AdHocContext.Driver.ExecuteDataSet( |
|
| 72 | + "SELECT DISTINCT [CategoryName], [ProductName] from [dbo].[Categories] left join [dbo].[Products] on [dbo].[Products].[CategoryID] = [dbo].[Categories].[CategoryID] order by [CategoryName], [ProductName]", |
|
| 73 | + false); |
|
| 74 | + System.Data.DataTable table = ds.Tables[0]; |
|
| 75 | + |
|
| 76 | + ValueTreeNode categoryNode = null; |
|
| 77 | + |
|
| 78 | + foreach (System.Data.DataRow row in table.Rows) { |
|
| 79 | + string category = row[0].ToString(); |
|
| 80 | + if (categoryNode == null || categoryNode.Text != category) { |
|
| 81 | + categoryNode = new ValueTreeNode(category); |
|
| 82 | + all.Nodes.Add(categoryNode); |
|
| 83 | + categoryNode.Nodes = new System.Collections.Generic.List<ValueTreeNode>(); |
|
| 84 | + } |
|
| 85 | + categoryNode.Nodes.Add(new ValueTreeNode(row[1].ToString())); |
|
| 86 | + |
|
| 87 | + } |
|
| 88 | + return result; |
|
| 89 | + } |
|
| 90 | + return base.GetPossibleValuesAsTree(fullColumnName, maxRowCount, rs); |
|
| 91 | + } |
|
| 92 | +``` |
|
| ... | ... | \ No newline at end of file |