Debian Codegraph @

dojox/grid/tests/enhanced/test_enhanced_grid_cellmerge.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5 <title>Test CellMerge plugin of dojox.grid.EnhancedGrid</title>
6 <link rel=stylesheet href="support/common.css"/>
7 <style type="text/css">
8 body {
9 font-size: 0.9em;
10 font-family: Geneva, Arial, Helvetica, sans-serif;
11 padding: 0.5em;
12 }
13 .title {
14 text-align:center;
15 margin:1em;
16 }
17 .container {
18 display: block;
19 border: 3px solid #ccc;
20 padding: 1em 3em;
21 cursor: default;
22 radius: 8pt;
23 background: #fff;
24 -moz-border-radius: 8pt 8pt;
25 display:inline-block;
26 }
27 table.merged th{
28 font-weight:bolder;
29 }
30 table.merged td{
31 text-align:center;
32 }
33 #grid{
34 margin-bottom: 30px;
35 width: 80em;
36 height: 30em;
37 }
38 /*Sample - overwrite default cell style
39 .claro .dojoxGridCell{
40 border-color: transparent #D5CDB5 #D5CDB5 transparent !important;
41 }
42 .dj_ie6 .claro .dojoxGridCell{
43 border: 1px solid #F1F1F1 !important;
44 }*/
45 </style>
46 <script type="text/javascript" src="../../../../dojo/dojo.js" data-dojo-config="isDebug:false, parseOnLoad: true"></script>
47 <script type="text/javascript" src="../../../../dijit/tests/_testCommon.js"></script>
48 <script type="text/javascript">
49 dojo.require("dojo.parser");
50 dojo.require("dijit.form.CheckBox");
51 dojo.require("dojo.data.ItemFileWriteStore");
52 dojo.require("dojox.grid.EnhancedGrid");
53 dojo.require("dojox.grid.enhanced.plugins.CellMerge");
54
55
56 var layout = [{
57 cells: [
58 { field: "id", name:"Identity", datatype:"number", width: 4, editable: false},
59 { field: "Genre", name:"Genre", datatype:"string", width: 10},
60 { field: "Artist", name:"Artist", datatype:"string", width: 10},
61 { field: "Year", name:"Year", datatype:"string", width: 2.5},
62 { field: "Album", name:"Album", datatype:"string", width: 10},
63 { field: "Name", name:"Name", datatype:"string", width: 8},
64 { field: "Length", name:"Length", datatype:"string", width: 4},
65 { field: "Track", name:"Track", datatype:"number", width: 3},
66 { field: "Composer", name:"Composer", datatype:"string", width: 12},
67 { field: "Download Date", name:"Download Date", datatype:"date", width: 12},
68 { field: "Last Played", name:"Last Played", datatype:"time", width: 6},
69 { field: "Heard", name: "Checked", datatype:"boolean", width: 6}
70 ]
71 }];
72 var plugins = {
73 cellMerge: {
74 "mergedCells": [
75 {row: 0, start: 0, end: 5, major: 2}
76 ]
77 }
78 };
79
80 var mergedCellHandles = [];
81 var lastChild = null;
82 function updateMergedCells(){
83 mergedCellHandles = [];
84 var grid = dijit.byId("grid");
85 var res = ["<tbody>"];
86 var mergedCells = grid.getMergedCells();
87 dojo.forEach(mergedCells, function(item, i){
88 mergedCellHandles.push(item.handle);
89 res.push("<tr><td>", item.row,
90 "</td><td>", item.start + 1,
91 "</td><td>", item.end + 1,
92 "</td><td>", item.major + 1,
93 "</td><td><button onclick=\"unmergeCells(",i,")\">Unmerge</button>",
94 "</td></tr>"
95 );
96 });
97 res.push("</tbody>");
98 lastChild && dojo.byId("tblMergedCells").removeChild(lastChild);
99 lastChild = dojo._toDom(res.join(''));
100 dojo.byId("tblMergedCells").appendChild(lastChild);
101 };
102 function mergeCells(){
103 var rowIndex = parseInt(dojo.byId("inputRow").value, 10);
104 var start = parseInt(dojo.byId("inputStart").value, 10);
105 var end = parseInt(dojo.byId("inputEnd").value, 10);
106 var major = parseInt(dojo.byId("inputMajor").value, 10);
107 var grid = dijit.byId("grid");
108 grid.mergeCells(rowIndex, start, end, major);
109 updateMergedCells();
110 };
111 function unmergeCells(handleIdx){
112 dijit.byId("grid").unmergeCells(mergedCellHandles[handleIdx]);
113 updateMergedCells();
114 };
115 var mergeByIndexHandle;
116 function toggleMergeByIndex(){
117 var grid = dijit.byId("grid");
118 if(mergeByIndexHandle){
119 grid.unmergeCells(mergeByIndexHandle);
120 mergeByIndexHandle = null;
121 }else{
122 mergeByIndexHandle = grid.mergeCells(function(rowIndex){
123 return rowIndex % 2;
124 }, 1, 3, 2);
125 }
126 }
127 var mergeByIdHandle;
128 function toggleMergeById(){
129 var grid = dijit.byId("grid");
130 if(mergeByIdHandle){
131 grid.unmergeCells(mergeByIdHandle);
132 mergeByIdHandle = null;
133 }else{
134 mergeByIdHandle = grid.mergeCells(function(rowIndex, item, store){
135 if(item){
136 var id = parseInt(store.getIdentity(item), 10);
137 return !(id % 2);
138 }
139 return false;
140 }, 4, 6, 5);
141 }
142 }
143 dojo.addOnLoad(updateMergedCells);
144 </script>
145 <script type="text/javascript" src="support/test_write_store_music.js"></script>
146 </head>
147 <body class="claro">
148 <h1 class="title">dojox.grid.EnhancedGrid - Cell Merge</h1>
149 <div id="gridContainer">
150 <div id="grid" dojoType="dojox.grid.EnhancedGrid" store="test_store[0]" structure="layout" plugins="plugins"></div>
151 </div><br/>
152 <div class="container">
153 <table>
154 <tr>
155 <td>At row (0 based)</td>
156 <td><input id="inputRow" type="text" value="5" size="3"/></td>
157 </tr>
158 <tr>
159 <td>From column</td>
160 <td><select id="inputStart">
161 <option value="0">1</option>
162 <option value="1">2</option>
163 <option value="2" selected="true">3</option>
164 <option value="3">4</option>
165 <option value="4">5</option>
166 <option value="5">6</option>
167 <option value="6">7</option>
168 <option value="7">8</option>
169 <option value="8">9</option>
170 <option value="9">10</option>
171 <option value="10">11</option>
172 </select></td>
173 <td>To column</td>
174 <td><select id="inputEnd">
175 <option value="0">1</option>
176 <option value="1">2</option>
177 <option value="2">3</option>
178 <option value="3">4</option>
179 <option value="4">5</option>
180 <option value="5">6</option>
181 <option value="6">7</option>
182 <option value="7" selected="true">8</option>
183 <option value="8">9</option>
184 <option value="9">10</option>
185 <option value="10">11</option>
186 </select></td>
187 </tr>
188 <tr>
189 <td>Use data of column</td>
190 <td><select id="inputMajor">
191 <option value="0">1</option>
192 <option value="1">2</option>
193 <option value="2">3</option>
194 <option value="3" selected="true">4</option>
195 <option value="4">5</option>
196 <option value="5">6</option>
197 <option value="6">7</option>
198 <option value="7">8</option>
199 <option value="8">9</option>
200 <option value="9">10</option>
201 <option value="10">11</option>
202 <option value="">(Use Default)</option>
203 </select></td>
204 </tr>
205 <tr>
206 <td colspan="2"><button onclick="mergeCells()">Merge Cells by Index</button></td>
207 </tr>
208 </table>
209 <h3>The Merged Cells</h3>
210 <table id="tblMergedCells" class="merged" cellpadding="1px" cellspacing="5px">
211 <thead><tr>
212 <th>
213 Row Index
214 </th>
215 <th>
216 Start Column
217 </th>
218 <th>
219 End Column
220 </th>
221 <th>
222 Major Column
223 </th>
224 </tr></thead>
225 </table>
226 </div>
227 <br />
228 <div class="container">
229 <div id="cb1" dojoType="dijit.form.CheckBox" onChange="toggleMergeByIndex()"></div><label for="cb1">Merge/Unmerge every second row by index</label><br />
230 <div id="cb2" dojoType="dijit.form.CheckBox" onChange="toggleMergeById()"></div><label for="cb2">Merge/Unmerge every second row by Identity</label>
231 </div>
232
233 <h3>Notes:</h3>
234 <ul>
235 <li>Cells can be merged at both design- and run-time.</li>
236 <li>Cell merging is done only in grid UI; the data store is not affected.</li>
237 <li>Column sorting and cell merging by index are incompatible, because sorting is store's job, while merging is grid's job, and after sorting, grid can not get the mapping between the new row order and the old one.)</li>
238 <li>Column sorting and merging by id are compatible.</li>
239 <li>To get currently merged cells, use grid.getMergedCells();</li>
240 <li>The merged cell will use as default the content of the cell at the leading edge, if major cell is not indicated.</li>
241 </ul>
242 <p><strong>Note:</strong> To see the tundra theme, just append <b style="color:blue;">?theme=tundra</b> to the URL.</p>
243 </body>
244 </html>