-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPivotTableRenderOption.cs
68 lines (63 loc) · 3.6 KB
/
PivotTableRenderOption.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace qyen.Pivot.Mvc5{
public enum HeaderType { Row, Column }
public enum MeasureArrangementType { Horisontal, Vertical }
public enum OutputPosition { Above, Below }
public class PivotTableRenderOption<T> {
public MeasureArrangementType MeasureArrangement { get; set; } = MeasureArrangementType.Horisontal;
public string TableCssClass { get; set; } = "pivot";
public string HeaderRowCssClass { get; set; } = "headerRow";
public string RowCssClass { get; set; } = "dataRow";
public string MeasureTitleCssClass { get; set; } = "measureTitle";
public bool RenderHeaderTitles { get; set; } = true;
public Dictionary<HeaderType, PivotAxisRenderOption> Header { get; } = new Dictionary<HeaderType, PivotAxisRenderOption>() {
{ HeaderType.Row , new PivotAxisRenderOption() {} },
{ HeaderType.Column , new PivotAxisRenderOption() {} },
};
private Dictionary<PivotMeasure<T>, Func<PivotTable<T>, PivotHeaderCell<T>, PivotHeaderCell<T>, PivotMeasure<T>, string>> measureFormatterDictionary
= new Dictionary<PivotMeasure<T>, Func<PivotTable<T>, PivotHeaderCell<T>, PivotHeaderCell<T>, PivotMeasure<T>, string>>();
private static Func<PivotTable<T>, PivotHeaderCell<T>, PivotHeaderCell<T>, PivotMeasure<T>, string> defaultCellRender
= (pivot, row, col, measure) => $"<td class=\"number\">{string.Format("{0:#,0}", (pivot[row, col, measure]))}</td>";
public PivotTableRenderOption<T> SetMeasureFormatter(PivotMeasure<T> measure, Func<PivotTable<T>, PivotHeaderCell<T>, PivotHeaderCell<T>, PivotMeasure<T>, string> formatFunction) {
if (measureFormatterDictionary.ContainsKey(measure)) {
measureFormatterDictionary[measure] = formatFunction;
} else {
measureFormatterDictionary.Add(measure, formatFunction);
}
return this;
}
internal string RenderMeasureCell(PivotTable<T> pivot, PivotHeaderCell<T> row, PivotHeaderCell<T> col, PivotMeasure<T> measure) {
if (measureFormatterDictionary.ContainsKey(measure)) {
return measureFormatterDictionary[measure](pivot, row, col, measure);
} else {
return defaultCellRender(pivot, row, col, measure);
}
}
public PivotAxisHeaderRenderOptions<T> HeaderCellOption { get; private set; } = new PivotAxisHeaderRenderOptions<T>();
}
public class PivotAxisRenderOption {
public bool RenderTotal { get; set; } = false;
public string TotalCssClass { get; set; } = "GrandTotal";
public string TotalTitle { get; set; } = Properties.Resources.GrandTotalCellTitle;
public OutputPosition TotalPosition { get; set; } = OutputPosition.Below;
}
public class PivotAxisHeaderRenderOptions<T> {
private Dictionary<PivotColumn<T>, PivotAxisRenderOption> options = new Dictionary<PivotColumn<T>, PivotAxisRenderOption>();
#pragma warning disable CA1043 // インデクサーには整数または文字列引数を使用します
public PivotAxisRenderOption this[PivotColumn<T> index] {
#pragma warning restore CA1043
get {
if (!options.ContainsKey(index)) {
options.Add(index, new PivotAxisRenderOption() {
TotalCssClass = "Total",
TotalTitle = Properties.Resources.TotalCellTitle,
});
}
return options[index];
}
}
}
}