FAQ/Questions/Add-Formatting-Options.md
... ...
@@ -23,6 +23,16 @@ We can also use an Izenda Format object as an argument. Below is the method of a
23 23
AdHocSettings.Formats.Add("Scientific", scientificFormat);
24 24
```
25 25
26
+###Results
27
+
28
+Below are screenshots of the results. The one directly below this text shows the OrderID field (a number field) with both of our new functions listed.
29
+
30
+![Extended Formats](/FAQ/Questions/Add-Formatting-Options/extended_formats.png)
31
+
32
+And here is the Freight field formatting options. Notice that we did not specify the "Money" type in our **SqlTypeGroups** for the Scientific format. Therefore, it is not listed in this dropdown but "Bold" still is.
33
+
34
+![Extended Formats 2](/FAQ/Questions/Add-Formatting-Options/extended_formats_2.png)
35
+
26 36
##Example 3 - International Date Formats
27 37
28 38
In this example, we show how to set the formats when using an International Date format. This example is for the European Date format.
... ...
@@ -33,12 +43,58 @@ In this example, we show how to set the formats when using an International Date
33 43
34 44
You can use this example as a template for other date formats as well.
35 45
36
-##Results
37
-
38
-Below are screenshots of the results. The one directly below this text shows the OrderID field (a number field) with both of our new functions listed.
46
+##Example 4 - Custom Formatters
39 47
40
-![Extended Formats](/FAQ/Questions/Add-Formatting-Options/extended_formats.png)
48
+In this example, we show how to create a custom formatter. You will add it to the [[Formatters collection for use in your application. This example is for the difference between time periods.
41 49
42
-And here is the Freight field formatting options. Notice that we did not specify the "Money" type in our **SqlTypeGroups** for the Scientific format. Therefore, it is not listed in this dropdown but "Bold" still is.
50
+You may use the DatesCustomFormatFormatter below as a reference. This will get inserted into your global.asax below your [[CustomAdHocConfig|http://wiki.izenda.us/API/AdHocConfig]] class definition. You can implement this custom formatter in your [[InitializeReporting()|]] method by creating a "new" DatesCustomFormatFormatter in the [[Formats|http://wiki.izenda.us/API/CodeSamples/Formats]] collection.
43 51
44
-![Extended Formats 2](/FAQ/Questions/Add-Formatting-Options/extended_formats_2.png)
... ...
\ No newline at end of file
0
+```csharp
1
+ [Serializable]
2
+ public class DatesCustomFormatFormatter : IFormatter {
3
+ public Type GetOutputDataType(DataTable table, int columnNumber, ReportOutputOptions reportOutputOptions, Field field) {
4
+ return typeof(string);
5
+ }
6
+
7
+ public object Format(DataTable table, int rowNumber, int columnNumber, Field field, DataTable originalTable, Field nameField) {
8
+ object value = table.Rows[rowNumber][columnNumber];
9
+ if (value == null || Convert.IsDBNull(value))
10
+ return null;
11
+ DateTime dateValue;
12
+
13
+ DateTime.TryParse(value.ToString(), out dateValue);
14
+ return dateValue.Day + " Days " + dateValue.Hour + " Hours " + dateValue.Minute + " Minutes " + dateValue.Second + " Seconds";
15
+ }
16
+ }
17
+
18
+ public class DatesCustomFormat : IFormat {
19
+ private SqlTypeGroupCollection allowedTypeGroups = new SqlTypeGroupCollection();
20
+ public SqlTypeGroupCollection AllowedTypeGroups {
21
+ get { return allowedTypeGroups; }
22
+ }
23
+
24
+ public SqlTypeGroupCollection DisallowedTypeGroups {
25
+ get { return null; }
26
+ }
27
+
28
+ public string Name { get; set; }
29
+
30
+ public SqlTypeGroup DefaultFor {
31
+ get { return SqlTypeGroup.None; }
32
+ }
33
+
34
+ public bool Visible {
35
+ get { return true; }
36
+ }
37
+
38
+ public IFormatter[] CreateFormatters() {
39
+ return new IFormatter[] { new DatesCustomFormatFormatter() };
40
+ }
41
+
42
+ public DatesCustomFormat(string name) {
43
+ allowedTypeGroups.Add(SqlTypeGroup.Date);
44
+ allowedTypeGroups.Add(SqlTypeGroup.DateTime);
45
+ Name = name;
46
+ }
47
+ }
48
+```
... ...
\ No newline at end of file