2150 |
mathias |
1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
|
2 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
3 |
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
4 |
<head>
|
|
|
5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
6 |
<title>Test dojox.Grid Editing</title>
|
|
|
7 |
<style type="text/css">
|
|
|
8 |
@import "../_grid/tundraGrid.css";
|
|
|
9 |
@import "../../../dojo/resources/dojo.css";
|
|
|
10 |
@import "../../../dijit/themes/tundra/tundra.css";
|
|
|
11 |
@import "../../../dijit/tests/css/dijitTests.css";
|
|
|
12 |
#controls button {
|
|
|
13 |
margin-left: 10px;
|
|
|
14 |
}
|
|
|
15 |
#grid {
|
|
|
16 |
width: 850px;
|
|
|
17 |
height: 350px;
|
|
|
18 |
border: 1px solid silver;
|
|
|
19 |
}
|
|
|
20 |
</style>
|
|
|
21 |
<script type="text/javascript" src="../../../dojo/dojo.js"
|
|
|
22 |
djConfig="isDebug: true, parseOnLoad: true"></script>
|
|
|
23 |
<script type="text/javascript" src="../../../dijit/tests/_testCommon.js"></script>
|
|
|
24 |
<script type="text/javascript">
|
|
|
25 |
dojo.require("dojox.grid.Grid");
|
|
|
26 |
dojo.require("dojox.grid._data.model");
|
|
|
27 |
dojo.require("dojox.grid._data.dijitEditors");
|
|
|
28 |
dojo.require("dojo.parser");
|
|
|
29 |
|
|
|
30 |
// ==========================================================================
|
|
|
31 |
// Create a data model
|
|
|
32 |
// ==========================================================================
|
|
|
33 |
|
|
|
34 |
s = (new Date()).getTime();
|
|
|
35 |
|
|
|
36 |
data = [
|
|
|
37 |
[ "normal", false, "new", 'But are not followed by two hexadecimal', 29.91, 10, false, s],
|
|
|
38 |
[ "important", false, "new", 'Because a % sign always indicates', 9.33, -5, false, s ],
|
|
|
39 |
[ "important", false, "read", 'Signs can be selectively', 19.34, 0, true, s ],
|
|
|
40 |
[ "note", false, "read", 'However the reserved characters', 15.63, 0, true, s ],
|
|
|
41 |
[ "normal", false, "replied", 'It is therefore necessary', 24.22, 5.50, true, s ],
|
|
|
42 |
[ "important", false, "replied", 'To problems of corruption by', 9.12, -3, true, s ],
|
|
|
43 |
[ "note", false, "replied", 'Which would simply be awkward in', 12.15, -4, false, s ]
|
|
|
44 |
];
|
|
|
45 |
var rows = 100;
|
|
|
46 |
for(var i=0, l=data.length; i<rows; i++){
|
|
|
47 |
data.push(data[i%l].slice(0));
|
|
|
48 |
}
|
|
|
49 |
model = new dojox.grid.data.Table(null, data);
|
|
|
50 |
// ==========================================================================
|
|
|
51 |
// Tie some UI to the data model
|
|
|
52 |
// ==========================================================================
|
|
|
53 |
model.observer(this);
|
|
|
54 |
modelChange = function(){
|
|
|
55 |
dojo.byId("rowCount").innerHTML = 'Row count: ' + model.count;
|
|
|
56 |
}
|
|
|
57 |
/*
|
|
|
58 |
modelInsertion = modelDatumChange = function(a1, a2, a3){
|
|
|
59 |
console.debug(a1, a2, a3);
|
|
|
60 |
}
|
|
|
61 |
*/
|
|
|
62 |
// ==========================================================================
|
|
|
63 |
// Custom formatters
|
|
|
64 |
// ==========================================================================
|
|
|
65 |
formatCurrency = function(inDatum){
|
|
|
66 |
return isNaN(inDatum) ? '...' : dojo.currency.format(inDatum, this.constraint);
|
|
|
67 |
}
|
|
|
68 |
formatDate = function(inDatum){
|
|
|
69 |
return dojo.date.locale.format(new Date(inDatum), this.constraint);
|
|
|
70 |
}
|
|
|
71 |
// ==========================================================================
|
|
|
72 |
// Grid structure
|
|
|
73 |
// ==========================================================================
|
|
|
74 |
statusCell = {
|
|
|
75 |
field: 2, name: 'Status',
|
|
|
76 |
styles: 'text-align: center;',
|
|
|
77 |
editor: dojox.grid.editors.Select,
|
|
|
78 |
options: [ "new", "read", "replied" ]
|
|
|
79 |
};
|
|
|
80 |
|
|
|
81 |
gridLayout = [{
|
|
|
82 |
type: 'dojox.GridRowView', width: '20px'
|
|
|
83 |
},{
|
|
|
84 |
defaultCell: { width: 8, editor: dojox.grid.editors.Input, styles: 'text-align: right;' },
|
|
|
85 |
rows: [[
|
|
|
86 |
{ name: 'Id',
|
|
|
87 |
get: function(inRowIndex) { return inRowIndex+1;},
|
|
|
88 |
editor: dojox.grid.editors.Dijit,
|
|
|
89 |
editorClass: "dijit.form.NumberSpinner" },
|
|
|
90 |
{ name: 'Date', width: 10, field: 7,
|
|
|
91 |
editor: dojox.grid.editors.DateTextBox,
|
|
|
92 |
formatter: formatDate,
|
|
|
93 |
constraint: {formatLength: 'long', selector: "date"}},
|
|
|
94 |
{ name: 'Priority', styles: 'text-align: center;', field: 0,
|
|
|
95 |
editor: dojox.grid.editors.ComboBox,
|
|
|
96 |
options: ["normal", "note", "important"], width: 10},
|
|
|
97 |
{ name: 'Mark', width: 3, styles: 'text-align: center;',
|
|
|
98 |
editor: dojox.grid.editors.CheckBox},
|
|
|
99 |
statusCell,
|
|
|
100 |
{ name: 'Message', styles: '', width: '100%',
|
|
|
101 |
editor: dojox.grid.editors.Editor, editorToolbar: true },
|
|
|
102 |
{ name: 'Amount', formatter: formatCurrency, constraint: {currency: 'EUR'},
|
|
|
103 |
editor: dojox.grid.editors.Dijit, editorClass: "dijit.form.CurrencyTextBox" },
|
|
|
104 |
{ name: 'Amount', field: 4, formatter: formatCurrency, constraint: {currency: 'EUR'},
|
|
|
105 |
editor: dojox.grid.editors.Dijit, editorClass: "dijit.form.HorizontalSlider", width: 10}
|
|
|
106 |
]]
|
|
|
107 |
}];
|
|
|
108 |
// ==========================================================================
|
|
|
109 |
// UI Action
|
|
|
110 |
// ==========================================================================
|
|
|
111 |
addRow = function(){
|
|
|
112 |
grid.addRow([
|
|
|
113 |
"normal", false, "new",
|
|
|
114 |
'Now is the time for all good men to come to the aid of their party.',
|
|
|
115 |
99.99, 9.99, false
|
|
|
116 |
]);
|
|
|
117 |
}
|
|
|
118 |
</script>
|
|
|
119 |
</head>
|
|
|
120 |
<body>
|
|
|
121 |
<h1>dojox.Grid Basic Editing test</h1>
|
|
|
122 |
<br />
|
|
|
123 |
<div id="controls">
|
|
|
124 |
<button onclick="grid.refresh()">Refresh</button>
|
|
|
125 |
<button onclick="grid.edit.focusEditor()">Focus Editor</button>
|
|
|
126 |
<button onclick="grid.focus.next()">Next Focus</button>
|
|
|
127 |
<button onclick="addRow()">Add Row</button>
|
|
|
128 |
<button onclick="grid.removeSelectedRows()">Remove</button>
|
|
|
129 |
<button onclick="grid.edit.apply()">Apply</button>
|
|
|
130 |
<button onclick="grid.edit.cancel()">Cancel</button>
|
|
|
131 |
<button onclick="grid.singleClickEdit = !grid.singleClickEdit">Toggle singleClickEdit</button>
|
|
|
132 |
</div>
|
|
|
133 |
<br />
|
|
|
134 |
<div id="grid" jsId="grid" dojoType="dojox.Grid" model="model" structure="gridLayout"></div>
|
|
|
135 |
<br />
|
|
|
136 |
<div id="rowCount"></div>
|
|
|
137 |
</body>
|
|
|
138 |
</html>
|