I need to move some selected items from a list by clicking on a link or button.
Giving 4 options to the user:
Put all selected items once backward or forward, or instead put all to the top of the list or to the bottom of the list.
I found a Jquery plugin that I’m using called jquery.tinysort.js
Actually, I don’t need to use this plugin, could be any plugin or code, just need to work properly.
Follow a link to see a demo http://jsfiddle.net/dkwZZ/
Follow the html code:
<div>
<p>
<a onclick="$('ul#ordenar>li').tsort({attr:'id'});">REFRESH ORDER</a> or
<a onclick="$('ul#ordenar>li').tsort('div[class=checkTrue]');">ALL SELECTED TO TOP</a> or
<a onclick="$('ul#ordenar>li').tsort('div[class=checkFalse]');">ALL SELECTED TO BOTTOM</a> or
<a>ALL SELECTED ONCE UP</a> or
<a>ALL SELECTED ONCE DOWN</a>
</p>
<ul class="" id="ordenar">
<li id="0"><div class="checkTrue"></div>checkTrue teste0</li>
<li id="1"><div class="checkFalse"></div>checkFalse teste1</li>
<li id="2"><div class="checkFalse"></div>checkFalse teste2</li>
<li id="3"><div class="checkTrue"></div>checkTrue teste3</li>
<li id="4"><div class="checkFalse"></div>checkFalse teste4</li>
<li id="5"><div class="checkTrue"></div>checkTrue teste5</li>
</ul>
</div>
When ALL SELECTED ONCE UP the order of the list should be:
<ul class="" id="ordenar">
<li id="0"><div class="checkTrue"></div>checkTrue teste0</li>
<li id="1"><div class="checkFalse"></div>checkFalse teste1</li>
<li id="3"><div class="checkTrue"></div>checkTrue teste3</li>
<li id="2"><div class="checkFalse"></div>checkFalse teste2</li>
<li id="5"><div class="checkTrue"></div>checkTrue teste5</li>
<li id="4"><div class="checkFalse"></div>checkFalse teste4</li>
</ul>
When ALL SELECTED ONCE DOWN the order of the list should be:
<ul class="" id="ordenar">
<li id="1"><div class="checkFalse"></div>checkFalse teste1</li>
<li id="0"><div class="checkTrue"></div>checkTrue teste0</li>
<li id="2"><div class="checkFalse"></div>checkFalse teste2</li>
<li id="4"><div class="checkFalse"></div>checkFalse teste4</li>
<li id="3"><div class="checkTrue"></div>checkTrue teste3</li>
<li id="5"><div class="checkTrue"></div>checkTrue teste5</li>
</ul>
I will be eternally grateful if someone can help me.
Cheers!!!
I think I get it now, here’s something that should sort your elements without a plugin.
FIDDLE
Then stick some ID’s on those
<a>elements, and bind the clicks, use preventDefault if you’re having issues with the window jumping to the top or other trouble with anchors.