Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7745197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:57:12+00:00 2026-06-01T09:57:12+00:00

After such a speedy response to my last question I thought I’d try my

  • 0

After such a speedy response to my last question I thought I’d try my luck with another :o)

I’m using jQuery UI sortable to sort an ember view. Each item in the view is also a view (like a teaser).

I am adding sortable to the parent view on didInsertElement here.

<script type="text/x-handlebars">
  App.SimpleRowListView = Em.View.extend({
    didInsertElement: function() {
      this.$().sortable({
        handle: '.dragger',
        items: '.simple-row',
        axis: 'y',
        update: function(event, ui) {
          // update is probably the best event...
        }
     });
    },
  });
</script>

Whenever the list is updated I’d like to update my simpleRow.listPosition value to the current index of each .simple-row within it’s parent element

I started adding an updateListPosition function to the view used for each row

<script>
updateListPosition : function() {
  var index = $('#simple-row-wrapper .simple-row').index(this.$());
  this.getPath('content').set('listPosition',index);
},
</script>

With the aim I’d connect my UI update event to trigger this on each of the child views.

I’m now wandering whether the update event should call a function on the controller to loop over all objects and set the listPosition. But in the controller I cannot access this.$() and so can’t calculate the index

My plan was to use listPosition as a sorting property on the controller’s array. But if there are better ways of sorting the controller array so that it reflects the changes made using .sortable()

Thanks again. I think this might be one quite a few people will want an answer for at some point 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:57:14+00:00Added an answer on June 1, 2026 at 9:57 am

    You need to go through the views. You can either loop each calling your updateListPosition function (which is kind of a heavy job) or you can do something like this

    <script type="text/javascript">
      App.SimpleRowListView = Em.View.extend({
        didInsertElement: function() {
          var self = this;
          this.$().sortable({
            handle: '.dragger',
            items: '.simple-row',
            axis: 'y',
            update: function(event, ui) {
              var rows = self.$('.simple-row').toArray();
              rows.forEach(function(row) {
                var view = Ember.View.views[$(row).attr('id')];
                view.updateListPosition();
              });
            }
         });
        },
      });
    </script>
    

    Or one version that seems a little lighter:

    <script type="text/javascript">
      App.SimpleRowListView = Em.View.extend({
        didInsertElement: function() {
          var self = this;
          this.$().sortable({
            handle: '.dragger',
            items: '.simple-row',
            axis: 'y',
            update: function(event, ui) {
              var rows = self.$('.simple-row').toArray();
              rows.forEach(function(row, position) {
                var view = Ember.View.views[$(row).attr('id')];
                view. updateListPosition(position);
                // pass the new position provided by forEach here and use it instead of calculating again
              });
            }
         });
        },
      });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After updating to Parsec 3.1 from 2.x, code using many1, such as word =
In emacs, after an operation such as comment-region , the selected region is automatically
I have such view that handles user registration. After creating new user i want
After moving to the new server, I'm getting plenty of such notifications: A PHP
I didn't know that installing ruby is such a pain After lot of trouble
Previously, I used to use MFC collection classes such CArray and CMap . After
Using Visual Studio 2010 I believe it's working correctly, as in after any document
I originally thought this was a WordPress issue - but realize after hours of
I realize that this question is impossible to answer absolutely, but I'm only after
I wish to create a content rule for an event such that after expiry

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.