5
<title>Example: Multiple Lists - Outer Join</title>
6
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
<link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
<link rel="stylesheet" href="../assets/css/main.css">
9
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
<script src="../../build/yui/yui-min.js"></script>
15
<h1>Example: Multiple Lists - Outer Join</h1>
18
<a href="#toc" class="jump">Jump to Table of Contents</a>
22
<div class="yui3-u-3-4">
24
<div class="content"><div class="intro">
25
<p>This example makes multiple sortable lists that are outer joined together. In the example below you will see 2 lists.
26
Both lists are sortable, but List #1 can move its items into List #2 and they become sortable. However, List #2 <strong>can not</strong> move its items into List #1.</p>
42
list-style-type: none;
47
-moz-box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25);
48
-webkit-box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25);
49
box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25);
53
background-color: #B6BFDA;
54
border: 1px solid #7E869D;
57
background-color: #F2C89F;
58
border: 1px solid #B19C87;
99
background-repeat: no-repeat;
109
background-repeat: no-repeat;
112
.example .arrow div {
117
font-size: 1px; /* for IE */
118
background-color: #d9d9d9;
121
.example .arrow-full {
123
background-image: url(../assets/sortable/arrow-left.png);
126
.example .arrow-full em {
127
background-image: url(../assets/sortable/arrow-right.png);
130
.example .arrow-out {
134
.example .arrow-out em {
135
background-image: url(../assets/sortable/arrow-right.png);
140
background-image: url(../assets/sortable/arrow-left.png);
145
<div id="demo" class="yui3-g">
146
<div class="yui3-u-1-2">
147
<h4 class="no-toc">List 1</h4>
149
<li class="one indent1">1</li>
150
<li class="one indent2">2</li>
151
<li class="one indent3">3</li>
152
<li class="one indent4">4</li>
153
<li class="one indent5">5</li>
154
<li class="one indent6">6</li>
155
<li class="one indent7">7</li>
156
<li class="one indent8">8</li>
157
<li class="one indent9">9</li>
158
<li class="one indent10">10</li>
161
<div class="yui3-u-1-2">
162
<h4 class="no-toc">List 2</h4>
164
<li class="two">A</li>
165
<li class="two">B</li>
166
<li class="two">C</li>
167
<li class="two">D</li>
168
<li class="two">E</li>
169
<li class="two">F</li>
170
<li class="two">G</li>
171
<li class="two">H</li>
172
<li class="two">I</li>
173
<li class="two">J</li>
178
<div class="yui3-u-1 arrow arrow-out"><div></div><em></em></div>
182
YUI().use('dd-constrain', 'sortable', function(Y) {
183
var list1 = new Y.Sortable({
189
var list2 = new Y.Sortable({
195
list1.join(list2, 'outer');
202
<p><strong>Note: When using an outer or inner joined list, you must pick a moveType of 'move' or 'copy', the default 'swap' won't give you the results you expect.</strong></p>
203
<p>This example assumes that you have seen the Multiple Sortable Lists - Full Join example and continues from there.</p>
205
<h3 id="setting-up-the-list">Setting Up the List</h3>
206
<p>First we need to create the HTML structure for the lists. Since <code>Sortable</code> uses <code>Y.DD.Delegate</code>, we need to set up the delegation containers (<code>#list1, #lists2</code>) and the list items (<code>li</code>).</p>
208
<pre class="code prettyprint"><div id="demo" class="yui3-g">
209
<div class="yui3-u-1-2">
210
<h4 class="no-toc">List 1</h4>
211
<ul id="list1">
212
<li class="one">1</li>
213
<li class="one">2</li>
214
<li class="one">3</li>
215
<li class="one">4</li>
216
<li class="one">5</li>
217
<li class="one">6</li>
218
<li class="one">7</li>
219
<li class="one">8</li>
220
<li class="one">9</li>
221
<li class="one">10</li>
224
<div class="yui3-u-1-2">
225
<h4 class="no-toc">List 2</h4>
226
<ul id="list2">
227
<li class="two">A</li>
228
<li class="two">B</li>
229
<li class="two">C</li>
230
<li class="two">D</li>
231
<li class="two">E</li>
232
<li class="two">F</li>
233
<li class="two">G</li>
234
<li class="two">H</li>
235
<li class="two">I</li>
236
<li class="two">J</li>
239
</div></pre>
242
<p>Now we give the lists some CSS to make them visible.</p>
244
<pre class="code prettyprint">#demo h4 {
255
list-style-type: none;
260
-moz-box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25);
261
-webkit-box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25);
262
box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.25);
266
background-color: #B6BFDA;
267
border: 1px solid #7E869D;
270
background-color: #F2C89F;
271
border: 1px solid #B19C87;
276
<h3 id="setting-up-the-yui-instance">Setting Up the YUI Instance</h3>
277
<p>Now we need to create our YUI instance and tell it to load the <code>sortable</code> module.</p>
278
<p>In this example we are also going to attach a <code>DD</code> plugin to the <code>Sortable</code> instances.</p>
280
<pre class="code prettyprint">YUI().use('dd-constrain', 'sortable'</pre>
283
<h3 id="making-the-lists-draggable">Making the Lists Draggable</h3>
284
<p>Now that we have a YUI instance with the <code>sortable</code> module, we need to instantiate a <code>Sortable</code> instance on each of the lists.</p>
286
<pre class="code prettyprint">YUI().use('dd-constrain', 'sortable', function(Y) {
287
var list1 = new Y.Sortable({
288
container: '#list1',
289
nodes: 'li',
290
opacity: '.1'
293
var list2 = new Y.Sortable({
294
container: '#list2',
295
nodes: 'li',
296
opacity: '.1'
302
<h3 id="applying-a-dd-plugin">Applying a DD Plugin</h3>
303
<p>Since <code>Sortable</code> uses <code>DD.Delegate</code>, there is a dd instance available after instantiation.</p>
304
<p>The <code>DD.Delegate</code> reference is found on the <code>.delegate</code> property of the <code>Sortable</code>.
305
This <code>DD.Delegate</code> instance has a <code>DD.Drag</code> instance bound to the <code>dd</code> property on the <code>DD.Delegate</code>
308
<pre class="code prettyprint">list1.delegate.dd.plug(Y.Plugin.DDConstrained, {
309
constrain2node: '#demo'
311
list2.delegate.dd.plug(Y.Plugin.DDConstrained, {
312
constrain2node: '#demo'
315
<p>Applying the <code>Plugin.DDConstrained</code> to the <code>Sortable</code> instance.</p>
317
<pre class="code prettyprint">YUI().use('dd-constrain', 'sortable', function(Y) {
318
var list1 = new Y.Sortable({
319
container: '#list1',
320
nodes: 'li',
321
opacity: '.1'
324
var list2 = new Y.Sortable({
325
container: '#list2',
326
nodes: 'li',
327
opacity: '.1'
330
list1.delegate.dd.plug(Y.Plugin.DDConstrained, {
331
constrain2node: '#demo'
333
list2.delegate.dd.plug(Y.Plugin.DDConstrained, {
334
constrain2node: '#demo'
341
<h3 id="joining-the-lists">Joining the Lists</h3>
342
<p>Joining the lists is as simple as calling the <code>join</code> method on one list passing in another list. By default, we use a full join which joins both lists both ways.</p>
343
<p>You can optionally specify the join type: <code>inner</code> or <code>outer</code>. The <code>moveType</code> can also be specified on the list: <code>swap</code>, <code>move</code> or <code>copy</code>. <code>swap</code> is the default, as seen in this example.</p>
345
<pre class="code prettyprint">list1.join(list2); //Full join <-- both ways -->
346
list1.join(list2, 'outer'); //Outer join --> one way -->
347
list1.join(list2, 'inner'); //Inner join <-- one way <--</pre>
351
<h3 id="putting-it-together">Putting it together</h3>
353
<pre class="code prettyprint">YUI().use('dd-constrain', 'sortable', function(Y) {
354
var list1 = new Y.Sortable({
355
container: '#list1',
356
nodes: 'li',
357
opacity: '.1'
360
var list2 = new Y.Sortable({
361
container: '#list2',
362
nodes: 'li',
363
opacity: '.1'
366
list1.join(list2, 'outer');
373
<div class="yui3-u-1-4">
374
<div class="sidebar">
376
<div id="toc" class="sidebox">
378
<h2 class="no-toc">Table of Contents</h2>
384
<a href="#setting-up-the-list">Setting Up the List</a>
387
<a href="#setting-up-the-yui-instance">Setting Up the YUI Instance</a>
390
<a href="#making-the-lists-draggable">Making the Lists Draggable</a>
393
<a href="#applying-a-dd-plugin">Applying a DD Plugin</a>
396
<a href="#joining-the-lists">Joining the Lists</a>
399
<a href="#putting-it-together">Putting it together</a>
407
<div class="sidebox">
409
<h2 class="no-toc">Examples</h2>
413
<ul class="examples">
416
<li data-description="Create a simple sortable list.">
417
<a href="simple-sortable.html">Simple Sortable List</a>
422
<li data-description="Sortable list example with floated nodes.">
423
<a href="sortable-float.html">Floated List</a>
428
<li data-description="Multiple Sortable Lists that are separate from one another.">
429
<a href="sortable-multi.html">Multiple Lists</a>
434
<li data-description="Multiple Sortable Lists that are fully joined together.">
435
<a href="sortable-multi-full.html">Multiple Lists - Full Join</a>
440
<li data-description="Multiple Sortable Lists that are outer joined together.">
441
<a href="sortable-multi-out.html">Multiple Lists - Outer Join</a>
446
<li data-description="Multiple Sortable Lists that are inner joined together.">
447
<a href="sortable-multi-in.html">Multiple Lists - Inner Join</a>
452
<li data-description="A fish sorting example. Multiple sortable lists with floated nodes that are outer joined together.">
453
<a href="sortable-fish.html">Fish Sort - Multi Outer Join</a>
468
<script src="../assets/vendor/prettify/prettify-min.js"></script>
469
<script>prettyPrint();</script>