Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Updating alternative index value #204

Closed
geekgonecrazy opened this issue Jun 17, 2014 · 3 comments
Closed

Updating alternative index value #204

geekgonecrazy opened this issue Jun 17, 2014 · 3 comments
Labels

Comments

@geekgonecrazy
Copy link

I've got list with both a track by and and order by on it

<ul ui-sortable ng-model="products">
<li ng-repeat="product in products | orderBy: 'listIndex' track by product.listID" ng-controller="product">ID {{product.listIndex}}
</li>
</ul>

Then i've got a product controller that will update the server when the product is updated. I need it to update also when I rearrange.

Previously I had this done just watching for the $index to change. But with the track by and order by the index value never updates.

I've managed to add sortableOptions to the ui-sortable and get the product i'm dragging to update... but this doesn't work for all of the other ones.

$scope.sortableOptions = {
    stop: function(e, ui) {
        var originalIndex = ui.item.sortable.index;
        var newProdArray = ui.item.sortable.resort.$modelValue;

        newProdArray[originalIndex].listIndex = ui.item.index() + 1;
    },
    axis: 'y'
};

So how do I either get it to update $index or let me specify what to use as the index?

@geekgonecrazy
Copy link
Author

With out the orderBy seems to work some what. With just the orderBy it doesn't work at all.

@thgreasi
Copy link
Contributor

First of all,
take a look at #70 and the ordering example found in README and the final pen found in #172. You should not apply filters on the ng-repeat since (as found in README):

The items of ng-model must match the indexes of the generated DOM elements.

So,

  1. order your list in the controller
  2. use stop() to apply the new indexes to your property
  3. report them back to your service (if changed).

References found using github search: #70, #113, #122, #172

@dud3
Copy link

dud3 commented Nov 11, 2015

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants