forked from dojo/dojo1-dgrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselector.html
167 lines (159 loc) · 5.42 KB
/
selector.html
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
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Grid Selectors</title>
<meta name="viewport" content="width=570">
<style>
@import "../../dojo/resources/dojo.css";
@import "../css/skins/claro.css";
.heading {
font-weight: bold;
padding-bottom: 0.25em;
}
.dgrid {
width: 70%;
margin: 10px;
}
.field-col1 {
width: 40px;
}
#grid-complex .dgrid-cell-padding {
height: 2em; /* force consistent heights across columnset cells */
}
.dgrid-column-set-0 {
width: 42px;
}
</style>
<script src="../../dojo/dojo.js"
data-dojo-config="async: true"></script>
<script>
var getColumns;
require(["dojo/on", "dgrid/OnDemandGrid", "dgrid/selector", "dgrid/Selection", "dgrid/Keyboard", "dgrid/ColumnSet",
"dojo/_base/declare", "dojo/_base/array", "dojo/json", "dgrid/test/data/base", "dojo/domReady!"],
function(on, Grid, selector, Selection, Keyboard, ColumnSet, declare, arrayUtil, json, testStore){
on(document.body, "dgrid-select,dgrid-deselect",
function(event){
var msg = (event.type == "dgrid-deselect" ? "de" : "") + "selected";
console.log(event.grid.id + ": " + msg +
(event.parentType ? " (via " + event.parentType + "): " : ": "),
arrayUtil.map(event.rows, function(row){ return row.id; }).join(", "));
console.log("selection: ", json.stringify(event.grid.selection, null, " "));
}
);
getColumns = function(){
return {
col1: selector({ disabled: function(object){ return object.col1 == "note"; }}),
id: "ID",
col2: { label: 'Column 2', sortable: false },
col3: { label: 'Column 3' }
};
};
getColumnsWithoutSelector = function(){
return {
col1: "Note",
id: "ID",
col2: { label: 'Column 2', sortable: false },
col3: { label: 'Column 3' }
};
}
var SelectionGrid = declare([Grid, Selection, Keyboard]);
window.grid = new SelectionGrid({
store: testStore,
selectionMode: "none",
columns: getColumns(),
allowSelectAll: true
}, "grid");
window.grid2 = new SelectionGrid({
store: testStore,
selectionMode: "none",
columns: {
col1: selector({ label: "" }), // Test blank label
id: "ID",
col2: {label: 'Column 2', sortable: false},
col3: {label: 'Column 3'}
},
allowSelectAll: false
}, "grid2");
window.gridRadio = new SelectionGrid({
store: testStore,
selectionMode: "none",
allowSelect: function(row){ return row.data.col3 == "read"; },
columns: {
col1: selector({ label: 'Radio' }, "radio"),
id: "ID",
col2: {label: 'Column 2', sortable: false},
col3: {label: 'Column 3'}
}
}, "grid-radio");
window.gridNoSelector = new SelectionGrid({
store: testStore,
selectionMode: "none",
columns: getColumnsWithoutSelector()
}, "gridNoSelector");
window.gridComplex = new (declare([Grid, ColumnSet, Selection, Keyboard]))({
store: testStore,
columnSets: [
[
[
selector({ field: "col1", disabled: function(object){ return object.col1 == "note"; }})
]
], [
[
{ field: "id", label: "ID" },
{ field: "col2", label: "Column 2", sortable: false },
{ field: "col3", label: "Column 3" }
]
]
]
}, "grid-complex");
}
);
</script>
</head>
<body class="claro">
<h2>A grid with checkbox selectors, with select-all enabled
(top checkbox, and Ctrl/Cmd+A)</h2>
<div>
<button type="button" onclick="grid.set('selectionMode', 'none');">
Set selection mode to "none"</button>
<button type="button" onclick="grid.set('selectionMode', 'single');">
Set selection mode to "single"</button>
<button type="button" onclick="grid.set('selectionMode', 'multiple');">
Set selection mode to "multiple"</button>
<button type="button" onclick="grid.set('selectionMode', 'extended');">
Set selection mode to "extended"</button>
</div>
<div id="grid"></div>
<div> Tests for resetting columns (should not cause errors):
<button type="button" onclick="grid.set('columns', getColumns());">
Reset columns, including selector
</button>
<button type="button" onclick="grid.set('columns', getColumnsWithoutSelector());">
Reset columns, without selector
</button>
</div>
<h2>A grid with radio selectors</h2>
<div>
<button type="button" onclick="gridRadio.set('selectionMode', 'none');">
Set selection mode to "none"</button>
<button type="button" onclick="gridRadio.set('selectionMode', 'single');">
Set selection mode to "single" (to test sync)</button>
</div>
<div id="grid-radio"></div>
<h2>A grid with checkbox selectors, with select-all disabled, blank label in selector column</h2>
<div id="grid2"></div>
<h2>A grid, initially without a selector column</h2>
<div id="gridNoSelector"></div>
<div> Tests for resetting columns (should not cause errors, and selectors should work):
<button type="button" onclick="gridNoSelector.set('columns', getColumns());">
Reset columns, including selector
</button>
<button type="button" onclick="gridNoSelector.set('columns', getColumnsWithoutSelector());">
Reset columns, without selector
</button>
</div>
<h2>A grid with checkbox selectors and column sets</h2>
<div id="grid-complex"></div>
</body>
</html>