liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Test Grid Row Selectors</title>
        <meta name="viewport" content="width=570">
        <style>
            @import "../../dojo/resources/dojo.css";
            @import "../css/dgrid.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 {
                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/_base/lang", "dojo/on", "dgrid/OnDemandGrid", "dgrid/Selection", "dgrid/Selector", "dgrid/Keyboard", "dgrid/ColumnSet",
            "dojo/_base/declare", "dojo/_base/array", "dojo/dom-construct", "dojo/json", "dgrid/test/data/testStore", "dojo/domReady!"],
        function(lang, on, Grid, Selection, Selector, Keyboard, ColumnSet, declare, arrayUtil, domConstruct, 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: 'checkbox' },
                    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, Selector, Keyboard]);
 
            window.grid = new SelectionGrid({
                collection: testStore,
                selectionMode: "none",
                allowSelect: function(row){
                    return row.data.col1 !== "note";
                },
                columns: getColumns(),
                allowSelectAll: true
            }, "grid");
            window.grid2 = new SelectionGrid({
                collection: testStore,
                selectionMode: "none",
                columns: {
                    col1: { selector: 'checkbox', label: "" }, // Test blank label
                    id: "ID",
                    col2: {label: 'Column 2', sortable: false},
                    col3: {label: 'Column 3'}
                },
                allowSelectAll: false
            }, "grid2");
 
            window.gridRadio = new SelectionGrid({
                collection: testStore,
                selectionMode: "none",
                allowSelect: function(row){
                    return row.data.col3 !== "read";
                },
                columns: {
                    col1: { selector: 'radio', label: 'Radio' },
                    id: "ID",
                    col2: {label: 'Column 2', sortable: false},
                    col3: {label: 'Column 3'}
                }
            }, "grid-radio");
 
            window.gridNoSelector = new SelectionGrid({
                collection: testStore,
                selectionMode: "none",
                columns: getColumnsWithoutSelector()
            }, "gridNoSelector");
 
            window.gridMultipleSelector = new SelectionGrid({
                collection: testStore,
                selectionMode: "none",
                columns: {
                    col1: { selector: 'checkbox', label: '' },
                    id: "ID",
                    col2: {label: 'Column 2'},
                    col3: {label: 'Column 3'},
                    col4: { selector: 'checkbox' }
                },
                allowSelectAll: true
            }, "gridMultipleSelector");
 
            window.gridMultipleSelectorRadio = new SelectionGrid({
                collection: testStore,
                selectionMode: "none",
                columns: {
                    col1: { selector: "radio", label: '' },
                    id: "ID",
                    col2: {label: 'Column 2'},
                    col3: {label: 'Column 3'},
                    col4: { selector: "radio" }
                },
                allowSelectAll: true
            }, "gridMultipleSelectorRadio");
 
            window.gridMultipleSelectorNoAll = new SelectionGrid({
                collection: testStore,
                selectionMode: "none",
                columns: {
                    col1: { selector: 'checkbox', label: '' },
                    id: "ID",
                    col2: {label: 'Column 2'},
                    col3: {label: 'Column 3'},
                    col4: { selector: 'checkbox' }
                }
            }, "gridMultipleSelectorNoAll");
 
            window.gridComplex = new (declare([Grid, ColumnSet, Selection, Selector, Keyboard]))({
                collection: testStore,
                allowSelect: function(row){
                    return row.data.col1 !== "note";
                },
                columnSets: [
                    [
                        [
                            { selector: 'checkbox', field: "col1" }
                        ]
                    ],
                    [
                        [
                            { field: "id", label: "ID" },
                            { field: "col2", label: "Column 2", sortable: false },
                            { field: "col3", label: "Column 3" }
                        ]
                    ]
                ]
            }, "grid-complex");
 
            window.gridCustomRender = new SelectionGrid({
                collection: testStore,
                selectionMode: "none",
                columns: {
                    col1: {
                        selector: function(column, value, cell, object){
                            var input = column.grid._defaultRenderSelectorInput(lang.delegate(column, {selector: 'checkbox'}), value, cell, object);
                            domConstruct.create('span', { innerHTML: '>' }, input, 'before');
                            domConstruct.create('span', { innerHTML: '<' }, input, 'after');
                            return input;
                        }
                    },
                    id: "ID",
                    col2: {label: 'Column 2'},
                    col3: {label: 'Column 3'}
                },
                allowSelectAll: true
            }, "gridCustomRender");
        }
);
        </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,x 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>
        <h2>A grid with multiple row selector columns</h2>
        <div id="gridMultipleSelector"></div>
        <h2>A grid with multiple selector columns and no select all</h2>
        <div id="gridMultipleSelectorNoAll"></div>
        <h2>A grid with multiple radio selector columns</h2>
        <div id="gridMultipleSelectorRadio"></div>
        <h2>A grid with a custom selector rendering function</h2>
        <div id="gridCustomRender"></div>
    </body>
</html>