-
Notifications
You must be signed in to change notification settings - Fork 4
/
Default.aspx
156 lines (150 loc) · 7.83 KB
/
Default.aspx
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v18.2, Version=18.2.18.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var currentColumnName;
function OnBatchEditStartEditing(s, e) {
currentColumnName = e.focusedColumn.fieldName;
}
function OnBatchEditEndEditing(s, e) {
var label = ASPxClientControl.GetControlCollection().GetByName('label' + currentColumnName);
CalculateSummary(s, label, e.rowValues, e.visibleIndex, currentColumnName, false);
window.setTimeout(function () {
var rowTotal = 0;
for (var key in e.rowValues) {
if (s.GetColumn(key).fieldName == "Total")
continue;
rowTotal += e.rowValues[key].value;
}
s.batchEditApi.SetCellValue(e.visibleIndex, "Total", rowTotal, null, true);
var total = parseInt(labelMon.GetValue()) + parseInt(labelTue.GetValue()) + parseInt(labelWen.GetValue())
labelTotal.SetText(total);
}, 0);
}
function CalculateSummary(grid, labelSum, rowValues, visibleIndex, columnName, isDeleting) {
var originalValue = grid.batchEditApi.GetCellValue(visibleIndex, columnName);
var newValue = rowValues[(grid.GetColumnByField(columnName).index)].value;
var dif = isDeleting ? -newValue : newValue - originalValue;
labelSum.SetValue((parseInt(labelSum.GetValue()) + dif));
}
function OnBatchEditRowDeleting(s, e) {
var total = 0;
_iterateRowValues(s, e, function (label, columnFieldName) {
CalculateSummary(s, label, e.rowValues, e.visibleIndex, columnFieldName, true);
total += parseInt(label.GetValue());
});
labelTotal.SetText(total);
}
function OnChangesCanceling(s, e) {
if (s.batchEditApi.HasChanges())
setTimeout(function () {
s.Refresh();
}, 0);
}
function OnBatchEditRowRecovering(s, e) {
var total = 0;
_iterateRowValues(s, e, function (label, fn) {
var columnTotal = parseInt(label.GetValue()) + e.rowValues[(s.GetColumnByField(fn).index)].value;
label.SetValue(columnTotal);
total += parseInt(label.GetValue());
});
labelTotal.SetText(total);
}
function _iterateRowValues(s, e, f) {
for (var key in e.rowValues) {
var columnFieldName = s.GetColumn(key).fieldName;
if (columnFieldName == "Total")
continue;
var label = ASPxClientControl.GetControlCollection().GetByName('label' + columnFieldName);
f(label, columnFieldName);
}
}
var dict = [];
function OnEndCallback(s, e) {
if (dict.length == 0) return;
_iterateColumns(s, e, function (label, fn) {
var v = dict.find(x => x.name === 'label' + fn).value;
label.SetValue(v);
});
}
function OnBeginCallback(s, e) {
dict = []
if (e.command == ASPxClientGridViewCallbackCommand.UpdateEdit || e.command == ASPxClientGridViewCallbackCommand.Refresh) return;
_iterateColumns(s, e, function (label, fn) {
dict.push({
name: 'label' + fn,
value: label.GetValue()
});
});
}
function _iterateColumns(s, e, f) {
for (j = 0; j < s.GetColumnCount() ; j++) {
var columnFieldName = s.GetColumn(j).fieldName;
var label = ASPxClientControl.GetControlCollection().GetByName('label' + columnFieldName);
if (label) {
f(label, columnFieldName);
}
}
}
</script>
</head>
<body>
<form id="frmMain" runat="server">
<dx:ASPxGridView ID="Grid" runat="server" KeyFieldName="ID" Width="600" OnBatchUpdate="Grid_BatchUpdate"
OnRowInserting="Grid_RowInserting" OnRowUpdating="Grid_RowUpdating" OnRowDeleting="Grid_RowDeleting"
OnCustomUnboundColumnData="Grid_CustomUnboundColumnData" OnHtmlDataCellPrepared="Grid_HtmlDataCellPrepared"
ClientInstanceName="gridView">
<ClientSideEvents BatchEditChangesCanceling="OnChangesCanceling"
BatchEditRowRecovering="OnBatchEditRowRecovering"
BatchEditRowDeleting="OnBatchEditRowDeleting"
BatchEditStartEditing="OnBatchEditStartEditing"
BeginCallback="OnBeginCallback"
EndCallback="OnEndCallback"
BatchEditEndEditing="OnBatchEditEndEditing" />
<Columns>
<dx:GridViewCommandColumn ShowNewButtonInHeader="true" ShowDeleteButton="true"></dx:GridViewCommandColumn>
<dx:GridViewDataSpinEditColumn FieldName="Mon">
<PropertiesSpinEdit MinValue="0" MaxValue="9999"></PropertiesSpinEdit>
<FooterTemplate>
<dx:ASPxLabel ID="ASPxLabel1" runat="server" ClientInstanceName="labelMon" Text='<%# GetSummaryValue((Container.Column as GridViewDataColumn).FieldName) %>'>
</dx:ASPxLabel>
</FooterTemplate>
</dx:GridViewDataSpinEditColumn>
<dx:GridViewDataSpinEditColumn FieldName="Tue">
<PropertiesSpinEdit MinValue="0" MaxValue="9999"></PropertiesSpinEdit>
<FooterTemplate>
<dx:ASPxLabel ID="ASPxLabel1" runat="server" ClientInstanceName="labelTue" Text='<%# GetSummaryValue((Container.Column as GridViewDataColumn).FieldName) %>'>
</dx:ASPxLabel>
</FooterTemplate>
</dx:GridViewDataSpinEditColumn>
<dx:GridViewDataSpinEditColumn FieldName="Wen">
<PropertiesSpinEdit MinValue="0" MaxValue="9999"></PropertiesSpinEdit>
<FooterTemplate>
<dx:ASPxLabel ID="ASPxLabel1" runat="server" ClientInstanceName="labelWen" Text='<%# GetSummaryValue((Container.Column as GridViewDataColumn).FieldName) %>'>
</dx:ASPxLabel>
</FooterTemplate>
</dx:GridViewDataSpinEditColumn>
<dx:GridViewDataTextColumn FieldName="Total" UnboundType="Decimal" ReadOnly="true">
<Settings ShowEditorInBatchEditMode="false" />
<FooterTemplate>
<dx:ASPxLabel ID="ASPxLabel1" runat="server" ClientInstanceName="labelTotal" Text='<%# GetSummaryValue((Container.Column as GridViewDataColumn).FieldName) %>'>
</dx:ASPxLabel>
</FooterTemplate>
</dx:GridViewDataTextColumn>
</Columns>
<SettingsEditing Mode="Batch" />
<Settings ShowFooter="true" />
<TotalSummary>
<dx:ASPxSummaryItem SummaryType="Sum" FieldName="Mon" Tag="Mon_Sum" />
<dx:ASPxSummaryItem SummaryType="Sum" FieldName="Tue" Tag="Tue_Sum" />
<dx:ASPxSummaryItem SummaryType="Sum" FieldName="Wen" Tag="Wen_Sum" />
<dx:ASPxSummaryItem SummaryType="Sum" FieldName="Total" Tag="Total_Sum" />
</TotalSummary>
</dx:ASPxGridView>
</form>
</body>
</html>