|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Master and detail tables</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h1>Example: Master and detail tables</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><style scoped> |
|
|
29 |
.yui3-skin-sam .yui3-datatable-caption { |
|
|
30 |
font-size: 13px; |
|
|
31 |
font-style: normal; |
|
|
32 |
text-align: left; |
|
|
33 |
} |
|
|
34 |
|
|
|
35 |
.yui3-datatable-col-nchars { |
|
|
36 |
text-align: center; |
|
|
37 |
} |
|
|
38 |
|
|
|
39 |
.yui3-skin-sam .yui3-datatable tr.myhilite td { |
|
|
40 |
background-color: #C0ffc0; |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
#mtable tbody tr { |
|
|
44 |
cursor: pointer; |
|
|
45 |
} |
|
|
46 |
</style> |
|
|
47 |
|
|
|
48 |
<div class="intro"> |
|
|
49 |
<p>Demonstrates a method of linking two DataTables together. In this case we link a row selection within a Master (or "parent") table |
|
|
50 |
to creation of a separate Detail (or "child") table. This is a common usage case for datasets that may have related rows within |
|
|
51 |
different datasets or as a result of typical database one-to-many key relationships. |
|
|
52 |
</p> |
|
|
53 |
</div> |
|
|
54 |
|
|
|
55 |
<div id="template" class="example yui3-skin-sam dt-example yui3-g"> |
|
|
56 |
<div class="yui3-u-1-3" id="mtable"></div> |
|
|
57 |
|
|
|
58 |
<!-- This is the HTML section for the "Details" markup ... |
|
|
59 |
NOTE: it is hidden initially !! --> |
|
|
60 |
<div class="yui3-u-2-3" id="chars" style="display:none;"> |
|
|
61 |
<div id="dtable"></div> |
|
|
62 |
</div> |
|
|
63 |
</div> |
|
|
64 |
<script> |
|
|
65 |
YUI().use( "datatable", function (Y) { |
|
|
66 |
|
|
|
67 |
var animal_data = [ |
|
|
68 |
{ aname: 'Lions', chars:[ 'Leo', 'Simba', 'Elsa', 'Cowardly Lion' ] }, |
|
|
69 |
{ aname: 'Amoebas' }, |
|
|
70 |
{ aname: 'Tigers', chars:[ 'Shere Kahn', 'Tigger', 'Tony' ] }, |
|
|
71 |
{ aname: 'Mules', chars:[ 'Francis' ] }, |
|
|
72 |
{ aname: 'Bears', chars:[ 'Smokey', 'Reginald', 'Winnie-the-Pooh', 'Baloo', 'Yogi' ] }, |
|
|
73 |
{ aname: 'Snakes', chars:[ 'Kaa', 'The Serpent', 'Nagini' ] } |
|
|
74 |
]; |
|
|
75 |
|
|
|
76 |
// |
|
|
77 |
// Create the "parent" DataTable |
|
|
78 |
// |
|
|
79 |
var dt_master = new Y.DataTable({ |
|
|
80 |
columns : [ |
|
|
81 |
{ key:'aname', label:'Type' }, |
|
|
82 |
{ name:'nchars', label:'No. of Chars', |
|
|
83 |
formatter: function(o){ |
|
|
84 |
return ( o.data.chars ) ? o.data.chars.length : 0; |
|
|
85 |
} |
|
|
86 |
} |
|
|
87 |
], |
|
|
88 |
data : animal_data, |
|
|
89 |
width: 200, |
|
|
90 |
caption: 'Select an animal category below:' |
|
|
91 |
}).render("#mtable"); |
|
|
92 |
|
|
|
93 |
// |
|
|
94 |
// Add a new attribute to track the last TR clicked, |
|
|
95 |
// this is used in the details DT formatter below and later |
|
|
96 |
// in the row click handler <code>delegate</code> for row highlighting |
|
|
97 |
// |
|
|
98 |
// also setup a click listener to update the "selectedRow" attribute on TR |
|
|
99 |
// clicks |
|
|
100 |
// |
|
|
101 |
dt_master.addAttr("selectedRow", { value: null }); |
|
|
102 |
|
|
|
103 |
dt_master.delegate('click', function (e) { |
|
|
104 |
this.set('selectedRow', e.currentTarget); |
|
|
105 |
}, '.yui3-datatable-data tr', dt_master); |
|
|
106 |
|
|
|
107 |
// |
|
|
108 |
// Create the characters DataTable and render it (it is hidden initially) |
|
|
109 |
// |
|
|
110 |
var dt_detail = new Y.DataTable({ |
|
|
111 |
columns : [ |
|
|
112 |
{ name:'aname', label:'Animal Category', |
|
|
113 |
formatter: function(o){ |
|
|
114 |
// just retrieve the selected Master record and return the |
|
|
115 |
// "aname" column |
|
|
116 |
var parent_rec = dt_master.getRecord( |
|
|
117 |
dt_master.get('selectedRow') ); |
|
|
118 |
|
|
|
119 |
return parent_rec.get('aname'); |
|
|
120 |
} |
|
|
121 |
}, |
|
|
122 |
{ key:'char_name', label:'Character' } |
|
|
123 |
], |
|
|
124 |
data : [], |
|
|
125 |
strings : { |
|
|
126 |
emptyMessage : "No critter characters were found!" |
|
|
127 |
}, |
|
|
128 |
width: 350, |
|
|
129 |
caption: 'Characters of the category include:' |
|
|
130 |
}).render("#dtable"); |
|
|
131 |
|
|
|
132 |
// |
|
|
133 |
// Setup a listener to the Master "selectedRowChange" event (i.e. after a |
|
|
134 |
// row click) |
|
|
135 |
// |
|
|
136 |
dt_master.after('selectedRowChange', function (e) { |
|
|
137 |
|
|
|
138 |
var tr = e.newVal, // the Node for the TR clicked ... |
|
|
139 |
last_tr = e.prevVal, // " " " the last TR clicked ... |
|
|
140 |
rec = this.getRecord(tr); // the current Record for the clicked TR |
|
|
141 |
|
|
|
142 |
// |
|
|
143 |
// This if-block does double duty, |
|
|
144 |
// (a) it tracks the first click to toggle the "details" DIV to visible |
|
|
145 |
// (b) it un-hightlights the last TR clicked |
|
|
146 |
// |
|
|
147 |
if ( !last_tr ) { |
|
|
148 |
// first time thru ... display the Detail DT DIV that was hidden |
|
|
149 |
Y.one("#chars").show(); |
|
|
150 |
} else { |
|
|
151 |
last_tr.removeClass("myhilite"); |
|
|
152 |
} |
|
|
153 |
|
|
|
154 |
// |
|
|
155 |
// After unhighlighting, now highlight the current TR |
|
|
156 |
// |
|
|
157 |
tr.addClass("myhilite"); |
|
|
158 |
|
|
|
159 |
|
|
|
160 |
// |
|
|
161 |
// Collect the "chars" member of the parent record into an array of |
|
|
162 |
// objects with property name "aname" |
|
|
163 |
// |
|
|
164 |
var detail_data = []; |
|
|
165 |
if ( rec.get('chars') ) { |
|
|
166 |
Y.Array.each( rec.get('chars'), function(item){ |
|
|
167 |
detail_data.push( {char_name:item}); |
|
|
168 |
}); |
|
|
169 |
} |
|
|
170 |
|
|
|
171 |
// |
|
|
172 |
// Set the "detail_data" to the dt_detail DataTable |
|
|
173 |
// also update the heading in "acategory" |
|
|
174 |
// ( it automatically refreshes ) |
|
|
175 |
// |
|
|
176 |
dt_detail.setAttrs({ |
|
|
177 |
data: detail_data, |
|
|
178 |
caption: 'Characters of the <strong>' + rec.get('aname') + |
|
|
179 |
'</strong> category include:' |
|
|
180 |
}); |
|
|
181 |
}); |
|
|
182 |
|
|
|
183 |
}); |
|
|
184 |
|
|
|
185 |
</script> |
|
|
186 |
|
|
|
187 |
<h2>Sample Data</h2> |
|
|
188 |
|
|
|
189 |
<p>Let's assume we have an array of data that includes parent elements and children elements. The example we'll use defines several animal |
|
|
190 |
categories and for each category it provides the names of some common characters from literature or pop culture of each type (<em>except for the lowly |
|
|
191 |
amoeba, we couldn't think of any ...</em>).</p> |
|
|
192 |
<pre class="code prettyprint">var animal_data = [ |
|
|
193 |
{ aname: 'Lions', chars:[ 'Leo', 'Simba', 'Elsa', 'Cowardly Lion' ] }, |
|
|
194 |
{ aname: 'Amoebas' }, |
|
|
195 |
{ aname: 'Tigers', chars:[ 'Shere Kahn', 'Tigger', 'Tony' ] }, |
|
|
196 |
{ aname: 'Mules', chars:[ 'Francis' ] }, |
|
|
197 |
{ aname: 'Bears', chars:[ 'Smokey', 'Reginald', 'Winnie-the-Pooh', 'Baloo', 'Yogi' ] }, |
|
|
198 |
{ aname: 'Snakes', chars:[ 'Kaa', 'The Serpent', 'Nagini' ] } |
|
|
199 |
];</pre> |
|
|
200 |
|
|
|
201 |
|
|
|
202 |
<h2>The DataTables</h2> |
|
|
203 |
|
|
|
204 |
<p>Two DataTables are utilized for this example and for convenience they operate using the same <code>animal_data</code> JavaScript array. In most practical applications |
|
|
205 |
the data would probably be received from a remote source via DataSource or using the Model <code>sync</code> capability. |
|
|
206 |
</p> |
|
|
207 |
|
|
|
208 |
<h3>The "Master" table</h3> |
|
|
209 |
|
|
|
210 |
<p>Our primary DataTable consists of two columns, <code>aname</code> which is the category of the animals and the other column is |
|
|
211 |
a calculated (or "unbound") column that is populated by a custom formatter. The custom formatter for <code>nchars</code> simply returns the length of the <code>chars</code> array |
|
|
212 |
associated with the record, or zero if none are defined.</p> |
|
|
213 |
|
|
|
214 |
<pre class="code prettyprint">var dt_master = new Y.DataTable({ |
|
|
215 |
columns : [ |
|
|
216 |
{ key:'aname', label:'Type' }, |
|
|
217 |
{ name:'nchars', label:'No. of Chars', |
|
|
218 |
formatter: function(o){ |
|
|
219 |
return ( o.data.chars ) ? o.data.chars.length : 0; |
|
|
220 |
} |
|
|
221 |
} |
|
|
222 |
], |
|
|
223 |
data : animal_data, |
|
|
224 |
width: 200, |
|
|
225 |
caption: 'Select an animal category below:' |
|
|
226 |
}).render("#mtable");</pre> |
|
|
227 |
|
|
|
228 |
|
|
|
229 |
<p>Since we will need a click handler to track TR clicks on the Master DataTable, we will define a new |
|
|
230 |
attribute <code>selectedRow</code> and setup a TR click handler that assigns this attribute on a click.</p> |
|
|
231 |
|
|
|
232 |
<pre class="code prettyprint">// |
|
|
233 |
// Add a new attribute to track the last TR clicked, |
|
|
234 |
// this is used in the details DT formatter below and later |
|
|
235 |
// in the row click handler `delegate` for row highlighting |
|
|
236 |
// |
|
|
237 |
// also setup a click listener to update the "selectedRow" attribute on TR clicks |
|
|
238 |
// |
|
|
239 |
dt_master.addAttr("selectedRow", { value: null }); |
|
|
240 |
|
|
|
241 |
dt_master.delegate('click', function (e) { |
|
|
242 |
this.set('selectedRow', e.currentTarget); |
|
|
243 |
}, '.yui3-datatable-data tr', dt_master);</pre> |
|
|
244 |
|
|
|
245 |
|
|
|
246 |
<h3>The "Detail" table</h3> |
|
|
247 |
|
|
|
248 |
<p>We can proceed with defining the linked child table and rendering it initially because we have hidden |
|
|
249 |
this DataTable within a DIV with style <code>display:none;</code> (the DIV becomes visible on the first row click). This child DataTable consisits of |
|
|
250 |
another calculated (i.e. unbound) column <code>aname</code> (which just fills with the parent category name) and |
|
|
251 |
a column <code>char_name</code>. The data for this table is initially empty, but will be populated by the click handler.</p> |
|
|
252 |
|
|
|
253 |
<pre class="code prettyprint">var dt_detail = new Y.DataTable({ |
|
|
254 |
columns : [ |
|
|
255 |
{ name:'aname', label:'Animal Category', |
|
|
256 |
formatter: function(o){ |
|
|
257 |
// just retrieve the selected Master record and return the "aname" column |
|
|
258 |
var parent_rec = dt_master.getRecord( dt_master.get('selectedRow') ); |
|
|
259 |
return parent_rec.get('aname'); |
|
|
260 |
} |
|
|
261 |
}, |
|
|
262 |
{ key:'char_name', label:'Character' } |
|
|
263 |
], |
|
|
264 |
data : [], |
|
|
265 |
strings : { |
|
|
266 |
emptyMessage : "No critter characters were found!" |
|
|
267 |
}, |
|
|
268 |
width: 350, |
|
|
269 |
caption: 'Characters of the category include:' |
|
|
270 |
}).render("#dtable");</pre> |
|
|
271 |
|
|
|
272 |
|
|
|
273 |
<h2>The selectedRow Listener</h2> |
|
|
274 |
<p> |
|
|
275 |
The "glue" between the master and detail DataTables is the delegated click handler on |
|
|
276 |
the Master DataTable's rows -- or more specifically, the <code>selectedRowChange</code> event handler. When a row is clicked and the |
|
|
277 |
<code>selectedRow</code> is changed, the underlying record from the Master table is |
|
|
278 |
determined and the Detail DataTable is populated with the corresponding <code>chars</code> data from the clicked record. |
|
|
279 |
We also handle TR highlighting for the clicked row by toggling a background color within this delegate handler. |
|
|
280 |
</p> |
|
|
281 |
<pre class="code prettyprint">dt_master.after('selectedRowChange', function (e) { |
|
|
282 |
|
|
|
283 |
var tr = e.newVal, // the Node for the TR clicked ... |
|
|
284 |
last_tr = e.prevVal, // " " " the last TR clicked ... |
|
|
285 |
rec = this.getRecord(tr); // the current Record for the clicked TR |
|
|
286 |
|
|
|
287 |
// |
|
|
288 |
// This if-block does double duty, |
|
|
289 |
// (a) it tracks the first click to toggle the "details" DIV to visible |
|
|
290 |
// (b) it un-hightlights the last TR clicked |
|
|
291 |
// |
|
|
292 |
if ( !last_tr ) { |
|
|
293 |
// first time thru ... display the Detail DT DIV that was hidden |
|
|
294 |
Y.one("#chars").show(); |
|
|
295 |
} else { |
|
|
296 |
last_tr.removeClass("myhilite"); |
|
|
297 |
} |
|
|
298 |
|
|
|
299 |
// |
|
|
300 |
// After unhighlighting, now highlight the current TR |
|
|
301 |
// |
|
|
302 |
tr.addClass("myhilite"); |
|
|
303 |
|
|
|
304 |
|
|
|
305 |
// |
|
|
306 |
// Collect the "chars" member of the parent record into an array of |
|
|
307 |
// objects with property name "aname" |
|
|
308 |
// |
|
|
309 |
var detail_data = []; |
|
|
310 |
if ( rec.get('chars') ) { |
|
|
311 |
Y.Array.each( rec.get('chars'), function(item){ |
|
|
312 |
detail_data.push( {char_name:item}); |
|
|
313 |
}); |
|
|
314 |
} |
|
|
315 |
|
|
|
316 |
// |
|
|
317 |
// Set the "detail_data" to the dt_detail DataTable |
|
|
318 |
// also update the heading in "acategory" |
|
|
319 |
// ( it automatically refreshes ) |
|
|
320 |
// |
|
|
321 |
dt_detail.setAttrs({ |
|
|
322 |
data: detail_data, |
|
|
323 |
caption: 'Characters of the <strong>' + rec.get('aname') + |
|
|
324 |
'</strong> category include:' |
|
|
325 |
}); |
|
|
326 |
});</pre> |
|
|
327 |
|
|
|
328 |
|
|
|
329 |
<p> |
|
|
330 |
Note: In the case of the use of remote data via DataSource, the |
|
|
331 |
<code>selectedRowChange</code> handler could be modified to generate a <code>sendRequest</code> |
|
|
332 |
or similar remote call for the Detail data and the <code>on:success</code> handler |
|
|
333 |
could be setup to set the <code>data</code> attribute. |
|
|
334 |
</p> |
|
|
335 |
|
|
|
336 |
<h2>Full Source Code</h2> |
|
|
337 |
|
|
|
338 |
<h3>CSS</h3> |
|
|
339 |
<pre class="code prettyprint">.yui3-skin-sam .yui3-datatable-caption { |
|
|
340 |
font-size: 13px; |
|
|
341 |
font-style: normal; |
|
|
342 |
text-align: left; |
|
|
343 |
} |
|
|
344 |
|
|
|
345 |
.yui3-datatable-col-nchars { |
|
|
346 |
text-align: center; |
|
|
347 |
} |
|
|
348 |
|
|
|
349 |
.yui3-skin-sam .yui3-datatable tr.myhilite td { |
|
|
350 |
background-color: #C0ffc0; |
|
|
351 |
} |
|
|
352 |
|
|
|
353 |
#mtable tbody tr { /* Turn on cursor to show TR's are selectable on Master DataTable only */ |
|
|
354 |
cursor: pointer; |
|
|
355 |
}</pre> |
|
|
356 |
|
|
|
357 |
|
|
|
358 |
<h3>HTML Markup</h3> |
|
|
359 |
<p> |
|
|
360 |
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the |
|
|
361 |
page's <code><body></code> element or to a parent element of the widget in order to apply |
|
|
362 |
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>. |
|
|
363 |
</p> |
|
|
364 |
<pre class="code prettyprint"><div id="template" class="yui3-skin-sam dt-example yui3-g"> <!-- You need this skin class --> |
|
|
365 |
<div class="yui3-u-1-3" id="mtable"></div> |
|
|
366 |
|
|
|
367 |
<!-- This is the HTML section for the "Details" markup ... |
|
|
368 |
NOTE: it is hidden initially !! --> |
|
|
369 |
<div class="yui3-u-2-3" id="chars" style="display:none;"> |
|
|
370 |
<div id="dtable"></div> |
|
|
371 |
</div> |
|
|
372 |
</div></pre> |
|
|
373 |
|
|
|
374 |
|
|
|
375 |
<h3>Javascript</h3> |
|
|
376 |
<pre class="code prettyprint">YUI().use( "datatable", function (Y) { |
|
|
377 |
|
|
|
378 |
var animal_data = [ |
|
|
379 |
{ aname: 'Lions', chars:[ 'Leo', 'Simba', 'Elsa', 'Cowardly Lion' ] }, |
|
|
380 |
{ aname: 'Amoebas' }, |
|
|
381 |
{ aname: 'Tigers', chars:[ 'Shere Kahn', 'Tigger', 'Tony' ] }, |
|
|
382 |
{ aname: 'Mules', chars:[ 'Francis' ] }, |
|
|
383 |
{ aname: 'Bears', chars:[ 'Smokey', 'Reginald', 'Winnie-the-Pooh', 'Baloo', 'Yogi' ] }, |
|
|
384 |
{ aname: 'Snakes', chars:[ 'Kaa', 'The Serpent', 'Nagini' ] } |
|
|
385 |
]; |
|
|
386 |
|
|
|
387 |
// |
|
|
388 |
// Create the "parent" DataTable |
|
|
389 |
// |
|
|
390 |
var dt_master = new Y.DataTable({ |
|
|
391 |
columns : [ |
|
|
392 |
{ key:'aname', label:'Type' }, |
|
|
393 |
{ name:'nchars', label:'No. of Chars', |
|
|
394 |
formatter: function(o){ |
|
|
395 |
return ( o.data.chars ) ? o.data.chars.length : 0; |
|
|
396 |
} |
|
|
397 |
} |
|
|
398 |
], |
|
|
399 |
data : animal_data, |
|
|
400 |
width: 200, |
|
|
401 |
caption: 'Select an animal category below:' |
|
|
402 |
}).render("#mtable"); |
|
|
403 |
|
|
|
404 |
// |
|
|
405 |
// Add a new attribute to track the last TR clicked, |
|
|
406 |
// this is used in the details DT formatter below and later |
|
|
407 |
// in the row click handler `delegate` for row highlighting |
|
|
408 |
// |
|
|
409 |
// also setup a click listener to update the "selectedRow" attribute on TR |
|
|
410 |
// clicks |
|
|
411 |
// |
|
|
412 |
dt_master.addAttr("selectedRow", { value: null }); |
|
|
413 |
|
|
|
414 |
dt_master.delegate('click', function (e) { |
|
|
415 |
this.set('selectedRow', e.currentTarget); |
|
|
416 |
}, '.yui3-datatable-data tr', dt_master); |
|
|
417 |
|
|
|
418 |
// |
|
|
419 |
// Create the characters DataTable and render it (it is hidden initially) |
|
|
420 |
// |
|
|
421 |
var dt_detail = new Y.DataTable({ |
|
|
422 |
columns : [ |
|
|
423 |
{ name:'aname', label:'Animal Category', |
|
|
424 |
formatter: function(o){ |
|
|
425 |
// just retrieve the selected Master record and return the |
|
|
426 |
// "aname" column |
|
|
427 |
var parent_rec = dt_master.getRecord( |
|
|
428 |
dt_master.get('selectedRow') ); |
|
|
429 |
|
|
|
430 |
return parent_rec.get('aname'); |
|
|
431 |
} |
|
|
432 |
}, |
|
|
433 |
{ key:'char_name', label:'Character' } |
|
|
434 |
], |
|
|
435 |
data : [], |
|
|
436 |
strings : { |
|
|
437 |
emptyMessage : "No critter characters were found!" |
|
|
438 |
}, |
|
|
439 |
width: 350, |
|
|
440 |
caption: 'Characters of the category include:' |
|
|
441 |
}).render("#dtable"); |
|
|
442 |
|
|
|
443 |
// |
|
|
444 |
// Setup a listener to the Master "selectedRowChange" event (i.e. after a |
|
|
445 |
// row click) |
|
|
446 |
// |
|
|
447 |
dt_master.after('selectedRowChange', function (e) { |
|
|
448 |
|
|
|
449 |
var tr = e.newVal, // the Node for the TR clicked ... |
|
|
450 |
last_tr = e.prevVal, // " " " the last TR clicked ... |
|
|
451 |
rec = this.getRecord(tr); // the current Record for the clicked TR |
|
|
452 |
|
|
|
453 |
// |
|
|
454 |
// This if-block does double duty, |
|
|
455 |
// (a) it tracks the first click to toggle the "details" DIV to visible |
|
|
456 |
// (b) it un-hightlights the last TR clicked |
|
|
457 |
// |
|
|
458 |
if ( !last_tr ) { |
|
|
459 |
// first time thru ... display the Detail DT DIV that was hidden |
|
|
460 |
Y.one("#chars").show(); |
|
|
461 |
} else { |
|
|
462 |
last_tr.removeClass("myhilite"); |
|
|
463 |
} |
|
|
464 |
|
|
|
465 |
// |
|
|
466 |
// After unhighlighting, now highlight the current TR |
|
|
467 |
// |
|
|
468 |
tr.addClass("myhilite"); |
|
|
469 |
|
|
|
470 |
|
|
|
471 |
// |
|
|
472 |
// Collect the "chars" member of the parent record into an array of |
|
|
473 |
// objects with property name "aname" |
|
|
474 |
// |
|
|
475 |
var detail_data = []; |
|
|
476 |
if ( rec.get('chars') ) { |
|
|
477 |
Y.Array.each( rec.get('chars'), function(item){ |
|
|
478 |
detail_data.push( {char_name:item}); |
|
|
479 |
}); |
|
|
480 |
} |
|
|
481 |
|
|
|
482 |
// |
|
|
483 |
// Set the "detail_data" to the dt_detail DataTable |
|
|
484 |
// also update the heading in "acategory" |
|
|
485 |
// ( it automatically refreshes ) |
|
|
486 |
// |
|
|
487 |
dt_detail.setAttrs({ |
|
|
488 |
data: detail_data, |
|
|
489 |
caption: 'Characters of the <strong>' + rec.get('aname') + |
|
|
490 |
'</strong> category include:' |
|
|
491 |
}); |
|
|
492 |
}); |
|
|
493 |
|
|
|
494 |
});</pre> |
|
|
495 |
|
|
|
496 |
</div> |
|
|
497 |
</div> |
|
|
498 |
</div> |
|
|
499 |
|
|
|
500 |
<div class="yui3-u-1-4"> |
|
|
501 |
<div class="sidebar"> |
|
|
502 |
|
|
|
503 |
|
|
|
504 |
|
|
|
505 |
<div class="sidebox"> |
|
|
506 |
<div class="hd"> |
|
|
507 |
<h2 class="no-toc">Examples</h2> |
|
|
508 |
</div> |
|
|
509 |
|
|
|
510 |
<div class="bd"> |
|
|
511 |
<ul class="examples"> |
|
|
512 |
|
|
|
513 |
|
|
|
514 |
<li data-description="This example illustrates simple DataTable use cases."> |
|
|
515 |
<a href="datatable-basic.html">Basic DataTable</a> |
|
|
516 |
</li> |
|
|
517 |
|
|
|
518 |
|
|
|
519 |
|
|
|
520 |
<li data-description="DataTable loaded with JSON data from a remote webservice via DataSource.Get"> |
|
|
521 |
<a href="datatable-dsget.html">DataTable + DataSource.Get + JSON Data</a> |
|
|
522 |
</li> |
|
|
523 |
|
|
|
524 |
|
|
|
525 |
|
|
|
526 |
<li data-description="DataTable loaded with XML data from a remote webservice via DataSource.IO."> |
|
|
527 |
<a href="datatable-dsio.html">DataTable + DataSource.IO + XML Data</a> |
|
|
528 |
</li> |
|
|
529 |
|
|
|
530 |
|
|
|
531 |
|
|
|
532 |
<li data-description="Custom format data for display."> |
|
|
533 |
<a href="datatable-formatting.html">Formatting Row Data for Display</a> |
|
|
534 |
</li> |
|
|
535 |
|
|
|
536 |
|
|
|
537 |
|
|
|
538 |
<li data-description="DataTable with nested column headers."> |
|
|
539 |
<a href="datatable-nestedcols.html">Nested Column Headers</a> |
|
|
540 |
</li> |
|
|
541 |
|
|
|
542 |
|
|
|
543 |
|
|
|
544 |
<li data-description="DataTable with column sorting."> |
|
|
545 |
<a href="datatable-sort.html">Column Sorting</a> |
|
|
546 |
</li> |
|
|
547 |
|
|
|
548 |
|
|
|
549 |
|
|
|
550 |
<li data-description="DataTable with vertical and/or horizontal scrolling rows."> |
|
|
551 |
<a href="datatable-scroll.html">Scrolling DataTable</a> |
|
|
552 |
</li> |
|
|
553 |
|
|
|
554 |
|
|
|
555 |
|
|
|
556 |
<li data-description="Using DataTable's recordType attribute to create calculated, sortable columns."> |
|
|
557 |
<a href="datatable-recordtype.html">Sortable generated columns</a> |
|
|
558 |
</li> |
|
|
559 |
|
|
|
560 |
|
|
|
561 |
|
|
|
562 |
<li data-description="Populating one DataTable from details in the data of another."> |
|
|
563 |
<a href="datatable-masterdetail.html">Master and detail tables</a> |
|
|
564 |
</li> |
|
|
565 |
|
|
|
566 |
|
|
|
567 |
|
|
|
568 |
<li data-description="Checkbox column that retains checked state when sorting."> |
|
|
569 |
<a href="datatable-chkboxselect.html">Checkbox select column</a> |
|
|
570 |
</li> |
|
|
571 |
|
|
|
572 |
|
|
|
573 |
|
|
|
574 |
|
|
|
575 |
</ul> |
|
|
576 |
</div> |
|
|
577 |
</div> |
|
|
578 |
|
|
|
579 |
|
|
|
580 |
|
|
|
581 |
<div class="sidebox"> |
|
|
582 |
<div class="hd"> |
|
|
583 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
584 |
</div> |
|
|
585 |
|
|
|
586 |
<div class="bd"> |
|
|
587 |
<ul class="examples"> |
|
|
588 |
|
|
|
589 |
|
|
|
590 |
|
|
|
591 |
|
|
|
592 |
|
|
|
593 |
|
|
|
594 |
|
|
|
595 |
|
|
|
596 |
|
|
|
597 |
|
|
|
598 |
|
|
|
599 |
|
|
|
600 |
|
|
|
601 |
|
|
|
602 |
|
|
|
603 |
|
|
|
604 |
|
|
|
605 |
|
|
|
606 |
|
|
|
607 |
|
|
|
608 |
|
|
|
609 |
|
|
|
610 |
<li data-description="Shows how to instantiate multiple Panel instances, and use nested modality to interact with a Datatable."> |
|
|
611 |
<a href="../panel/panel-form.html">Creating a Modal Form</a> |
|
|
612 |
</li> |
|
|
613 |
|
|
|
614 |
|
|
|
615 |
</ul> |
|
|
616 |
</div> |
|
|
617 |
</div> |
|
|
618 |
|
|
|
619 |
</div> |
|
|
620 |
</div> |
|
|
621 |
</div> |
|
|
622 |
</div> |
|
|
623 |
|
|
|
624 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
625 |
<script>prettyPrint();</script> |
|
|
626 |
|
|
|
627 |
<script> |
|
|
628 |
YUI.Env.Tests = { |
|
|
629 |
examples: [], |
|
|
630 |
project: '../assets', |
|
|
631 |
assets: '../assets/datatable', |
|
|
632 |
name: 'datatable-masterdetail', |
|
|
633 |
title: 'Master and detail tables', |
|
|
634 |
newWindow: '', |
|
|
635 |
auto: false |
|
|
636 |
}; |
|
|
637 |
YUI.Env.Tests.examples.push('datatable-basic'); |
|
|
638 |
YUI.Env.Tests.examples.push('datatable-dsget'); |
|
|
639 |
YUI.Env.Tests.examples.push('datatable-dsio'); |
|
|
640 |
YUI.Env.Tests.examples.push('datatable-formatting'); |
|
|
641 |
YUI.Env.Tests.examples.push('datatable-nestedcols'); |
|
|
642 |
YUI.Env.Tests.examples.push('datatable-sort'); |
|
|
643 |
YUI.Env.Tests.examples.push('datatable-scroll'); |
|
|
644 |
YUI.Env.Tests.examples.push('datatable-recordtype'); |
|
|
645 |
YUI.Env.Tests.examples.push('datatable-masterdetail'); |
|
|
646 |
YUI.Env.Tests.examples.push('datatable-chkboxselect'); |
|
|
647 |
YUI.Env.Tests.examples.push('panel-form'); |
|
|
648 |
|
|
|
649 |
</script> |
|
|
650 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
651 |
|
|
|
652 |
|
|
|
653 |
|
|
|
654 |
</body> |
|
|
655 |
</html> |