Re: Moving options between two multi select boxes when triggered by buttons? Best way with Angular?

6,190 views
Skip to first unread message
Message has been deleted

Matt Raible

unread,
Mar 23, 2013, 3:32:01 PM3/23/13
to ang...@googlegroups.com
This works great for moving items between two selects. Do you have something similar for re-ordering the items in the select?

On Saturday, June 16, 2012 8:51:17 AM UTC-6, Andy Joslin wrote:
You can do it pretty simply: http://jsfiddle.net/andytjoslin/aeSaJ/3/

Matt Raible

unread,
Mar 23, 2013, 8:11:10 PM3/23/13
to ang...@googlegroups.com
Figured it out.

<button ng-click="moveUp(selected[0], items)">Move Up</button>
<button ng-click="moveDown(selected[0], items)">Move Down</button>

select size=10 ng-model="selected" ng-options="i.title for i in items" multiple="multiple"></select>

And in my controller:

    $scope.moveUp = function(item, list) {
        var idx = list.indexOf(item);
        if (idx != -1) {
            list.splice(idx - 1, 0, list.splice(idx, 1)[0]);
        }
    };

    $scope.moveDown = function(item, list) {
        var idx = list.indexOf(item);
        if (idx != -1) {
            list.splice(idx + 1, 0, list.splice(idx, 1)[0]);
        }
    };

Hope this helps someone in the future.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/cyw1j3iarNc/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

sweta_...@lexia-analytics.com

unread,
Jun 17, 2014, 5:10:19 AM6/17/14
to ang...@googlegroups.com
Plz help me with this.
http://jsfiddle.net/aeSaJ/141/

Scott Howser

unread,
Aug 27, 2014, 9:55:06 AM8/27/14
to ang...@googlegroups.com
This is a very nice example I created. 100% angular and hase some nice features.

Raildo Almeida

unread,
Aug 25, 2015, 1:04:10 PM8/25/15
to AngularJS
Tks Scott, this saved me a lot of time.
Message has been deleted

Yousuf Mama

unread,
May 12, 2016, 12:32:55 PM5/12/16
to AngularJS
@Scott Howser do you have any idea on how to integrate these buttons code with angular-drag-and-drop library?
Reply all
Reply to author
Forward
0 new messages