-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathNimbleTableColumnEnumBase.cs
92 lines (80 loc) · 2.68 KB
/
NimbleTableColumnEnumBase.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Components;
namespace NimbleBlazor;
public class NimbleTableColumnEnumBase<TKey> : NimbleTableColumn, IGroupableColumn, ISortableColumn
{
/// <summary>
/// Gets or sets the field in the element representing a row of data in a <see cref="NimbleTable{TData}"/>to display
/// </summary>
[Parameter]
[DisallowNull]
public string FieldName { get; set; } = null!;
[Parameter]
public RenderFragment? ChildContent { get; set; }
/// <summary>
/// Specifies the grouping precedence of the column within the set of all columns participating in grouping.
/// Columns are rendered in the grouping tree from lowest group-index as the tree root to highest
/// group-index as tree leaves.
/// </summary>
[Parameter]
public int? GroupIndex { get; set; }
/// <summary>
/// Whether or not this column can be used to group rows by
/// </summary>
[Parameter]
public bool? GroupingDisabled { get; set; }
/// <summary>
/// The direction the column is sorted.
/// </summary>
[Parameter]
public TableColumnSortDirection? SortDirection { get; set; }
/// <summary>
/// The index for sorting the column. When multiple columns are sorted,
/// they will be sorted from lowest index to highest index.
/// </summary>
[Parameter]
public int? SortIndex { get; set; }
/// <summary>
/// Whether or not sorting is disabled on the column. If sorting is disabled, the column
/// will not be sorted even if <see cref="SortIndex"/> and <see cref="SortDirection"/> are configured.
/// </summary>
[Parameter]
public bool? SortingDisabled { get; set; }
private readonly Type[] supportedCSharpNumberTypes = new[]
{
typeof(int),
typeof(uint),
typeof(short),
typeof(ushort),
typeof(byte),
typeof(sbyte),
typeof(float),
typeof(double)
};
private readonly Type[] unsupportedCSharpNumberTypes = new[]
{
typeof(long),
typeof(ulong),
typeof(decimal)
};
protected string GetTKeyAsJSType()
{
if (supportedCSharpNumberTypes.Contains(typeof(TKey)))
{
return "number";
}
if (typeof(TKey) == typeof(bool))
{
return "boolean";
}
if (typeof(TKey) == typeof(string))
{
return "string";
}
if (unsupportedCSharpNumberTypes.Contains(typeof(TKey)))
{
throw new ArgumentException("TKey was an unsupported numeric type.");
}
throw new ArgumentException("TKey was not a numeric, boolean, or string.");
}
}