-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.cshtml
76 lines (69 loc) · 2.58 KB
/
Index.cshtml
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
@using ASP_NET_Core.Models
<h2>Home</h2>
<script type="text/javascript">
const nonZeroFormat = '##.######';
const zeroFormat = '0#.######';
const currencyFormat = '$ #,##0.##';
function onContentReady(e) {
if (!e.component.isLoaded) {
e.component.isLoaded = true;
if (e.component.option('value') === 0) { e.component.option('format', zeroFormat); }
}
}
function onNonZeroKeyDown(e) {
const value = e.component.option('value');
if (e.event?.key === '0' && value === null) {
e.component.option('format', zeroFormat);
} else if (e.event?.key === 'Backspace' && value === 0) {
e.component.option('format', '');
} else if (value != null && (value > -1 && value < 1)) {
e.component.option('format', zeroFormat);
} else {
e.component.option('format', nonZeroFormat);
}
}
function onZeroKeyDown(e) {
if (e.event?.key === 'Backspace' && e.component.option('value') === 0) {
e.component.option('format', '');
} else {
e.component.option('format', currencyFormat);
}
}
function onEditorPreparing(e) {
if (e.parentType !== 'filterRow') return;
if (e.dataField === 'PaymentId') {
e.editorOptions.onContentReady = onContentReady;
e.editorOptions.onKeyDown = onNonZeroKeyDown;
}
if (e.dataField === 'Amount') {
e.editorOptions.onKeyDown = onZeroKeyDown;
}
}
</script>
@(Html.DevExtreme().NumberBox()
.Format("$ #,##0.##")
.Width(400)
.Label("zero-based format")
.ValueChangeEvent("keyup")
.OnKeyDown("onZeroKeyDown")
)
@(Html.DevExtreme().NumberBox()
.Format("##.######")
.Width(400)
.Label("non-zero format")
.ValueChangeEvent("keyup")
.OnKeyDown("onNonZeroKeyDown")
.OnContentReady("onContentReady")
)
@(Html.DevExtreme().DataGrid<PaymentInfo>()
.ShowBorders(true)
.DataSource(d => d.Mvc().Controller("SampleData").LoadAction("Get").Key("PaymentId"))
.OnEditorPreparing("onEditorPreparing")
.Columns(columns =>
{
columns.AddFor(m => m.PaymentId).Caption("Payment Id (non-zero format)").Width(200).AllowEditing(false).Format("##.######").EditorOptions(new { format = "##.######" });
columns.AddFor(m => m.Amount).Caption("Amount (zero-based format)").AllowEditing(false).Format("$ #,##0.##").EditorOptions(new { format = "$ #,##0.##" });
columns.AddFor(m => m.PaymentDate);
})
.FilterRow(f => f.Visible(true).ApplyFilter(GridApplyFilterMode.Auto))
)