开发者

jquery: tinysort.. "unsort" method to restore default order?

I'm using tinysort pl开发者_如何学Cugin on jQuery and it works great.

However I would like if there is an "unsort" option, to restore the default order of my elements.

Thanks


My advice would be output the index of your list items (or whatever) in a hidden span and then in your undo button sort on that.


I solved in this way:

var alphaOrder = defaultOrder.clone();

and then:

defaultOrder.remove(); alphaOrder.tsort("label").each(function(i){$(this)}); tagsDiv.append(alphaOrder);

and viceversa.


I know this is an old thread but I had a similar problem and I came up with a different solution. So, hopefully, this might help future users:

Before running tsort on your elements, try looping over all of them and setting an order using data attributes:

n = 1;
$('ul>li').each(function(index, value) {
    $this = $(this);  // cache for speed/memory usage
    $this.data({'orig': n});
}
// do other stuff you might want to do
$('#unsort').click(function(e) {
    e.preventDefault();
    $('ul>li').tsort({data:'orig',order:'asc'});
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜