aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/grid/tests/test_edit_dijit.html
blob: 484c7e5864b096195e51027169f1cc2e2f64bd64 (plain)
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
<!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>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Test dojox.Grid Editing</title>
	<style type="text/css">
		@import "../_grid/tundraGrid.css";
		@import "../../../dojo/resources/dojo.css";
		@import "../../../dijit/themes/tundra/tundra.css";
		@import "../../../dijit/themes/tundra/tundra_rtl.css";
		@import "../../../dijit/tests/css/dijitTests.css";
		#controls button {
			margin-left: 10px;
		}
		#grid {
			width: 850px;
			height: 350px;
			border: 1px solid silver;
		}
		</style>
	<script type="text/javascript" src="../../../dojo/dojo.js" 
		djConfig="isDebug: true, parseOnLoad: true"></script>
	<script type="text/javascript" src="../../../dijit/tests/_testCommon.js"></script>
	<script type="text/javascript">
		dojo.require("dojox.grid.Grid");
		dojo.require("dojo.parser");

		// ==========================================================================
		// Create a data model
		// ==========================================================================
		
		s = (new Date()).getTime();
		
		data = [ 
			[ "normal", false, "new", 'But are not followed by two hexadecimal', 29.91, 10, false, s],
			[ "important", false, "new", 'Because a % sign always indicates', 9.33, -5, false, s ],
			[ "important", false, "read", 'Signs can be selectively', 19.34, 0, true, s ],
			[ "note", false, "read", 'However the reserved characters', 15.63, 0, true, s ],
			[ "normal", false, "replied", 'It is therefore necessary', 24.22, 5.50, true, s ],
			[ "important", false, "replied", 'To problems of corruption by', 9.12, -3, true, s ],
			[ "note", false, "replied", 'Which would simply be awkward in', 12.15, -4, false, s ]
		];
		var rows = 100;
		for(var i=0, l=data.length; i<rows; i++){
			data.push(data[i%l].slice(0));
		}
		model = new dojox.grid.data.Table(null, data);
		// ==========================================================================
		// Tie some UI to the data model
		// ==========================================================================
		model.observer(this);
		modelChange = function(){
			dojo.byId("rowCount").innerHTML = 'Row count: ' + model.count; 
		}
		/*
		modelInsertion = modelDatumChange = function(a1, a2, a3){
			console.debug(a1, a2, a3);
		}
		*/
		// ==========================================================================
		// Custom formatters
		// ==========================================================================
		formatCurrency = function(inDatum){
			return isNaN(inDatum) ? '...' : dojo.currency.format(inDatum, this.constraint);
		}
		formatDate = function(inDatum){
			return dojo.date.locale.format(new Date(inDatum), this.constraint);
		}
		// ==========================================================================
		// Grid structure
		// ==========================================================================
		statusCell = {
			field: 2, name: 'Status', 
			styles: 'text-align: center;', 
			editor: dojox.grid.editors.Select, 
			options: [ "new", "read", "replied" ]
		};

		gridLayout = [{
			type: 'dojox.GridRowView', width: '20px'
		},{
			defaultCell: { width: 8, editor: dojox.grid.editors.Input, styles: 'text-align: right;'  },
			rows: [[
				{ name: 'Id', 
					get: function(inRowIndex) { return inRowIndex+1;}, 
					editor: dojox.grid.editors.Dijit,
					editorClass: "dijit.form.NumberSpinner" },
				{ name: 'Date', width: 10, field: 7, 
					editor: dojox.grid.editors.DateTextBox, 
					formatter: formatDate, 
					constraint: {formatLength: 'long', selector: "date"}},
				{ name: 'Priority', styles: 'text-align: center;', field: 0, 
					editor: dojox.grid.editors.ComboBox, 
					options: ["normal", "note", "important"], width: 10},
				{ name: 'Mark', width: 3, styles: 'text-align: center;', 
					editor: dojox.grid.editors.CheckBox},
				statusCell,
				{ name: 'Message', styles: '', width: '100%', 
					editor: dojox.grid.editors.Editor, editorToolbar: true },
				{ name: 'Amount', formatter: formatCurrency, constraint: {currency: 'EUR'}, 
					editor: dojox.grid.editors.Dijit, editorClass: "dijit.form.CurrencyTextBox" },
				{ name: 'Amount', field: 4, formatter: formatCurrency, constraint: {currency: 'EUR'}, 
					editor: dojox.grid.editors.Dijit, editorClass: "dijit.form.HorizontalSlider", width: 10}
			]]
		}];
		// ==========================================================================
		// UI Action
		// ==========================================================================
		addRow = function(){
			grid.addRow([
				"normal", false, "new", 
				'Now is the time for all good men to come to the aid of their party.', 
				99.99, 9.99, false 
			]);
		}
	</script>
</head>
<body>
	<h1>dojox.Grid Basic Editing test</h1>
	<br />
	<div id="controls">
		<button onclick="grid.refresh()">Refresh</button>
		<button onclick="grid.edit.focusEditor()">Focus Editor</button>
		<button onclick="grid.focus.next()">Next Focus</button>
		<button onclick="addRow()">Add Row</button>
		<button onclick="grid.removeSelectedRows()">Remove</button>
		<button onclick="grid.edit.apply()">Apply</button>
		<button onclick="grid.edit.cancel()">Cancel</button>
		<button onclick="grid.singleClickEdit = !grid.singleClickEdit">Toggle singleClickEdit</button>
	</div>
	<br />
	<div id="grid" jsId="grid" dojoType="dojox.Grid" model="model" structure="gridLayout"></div>
	<br />
	<div id="rowCount"></div>
</body>
</html>