2

I found ui sortable and got it working nicely for simple lists and the like. My application already uses the ui-bootstrap and I want to sort the accordion elements.

The html looks nice:

<div ng:controller="controller">
    <accordion ui:sortable ng:model="list">
        <accordion-group ng:repeat="item in list" class="item">
            <accordion-heading>{{item}}</accordion-heading>
        </accordion-group>
    </accordion>
</div>

However, while this works with the accordion bits swapped for ul/li etc. it does not work for the accordion element. Here is the non working fiddle. The drag action just picks up the entire accordion.

Is this a bug or am I doing something wrong?

2 Answers 2

5

I've came across this trouble. I've solved using a $decorator, which is very useful to edit third-party libraries without touching the core. The exactly code is:

yourModule.config(['$provide', function ($provide){
    $provide.decorator('accordionDirective', function($delegate) { 
        var directive = $delegate[0];
        directive.replace = true;
        return $delegate;
    });
}]);

What the code does is replace the template that the accordion directive is wrapping, so now the ng-repeat is a direct child of the ui-sortable directive, and it should work.

Also, as @Dylan says, I suggest to use a "handler" to prevent the accordion from opening when sorting.

Sign up to request clarification or add additional context in comments.

4 Comments

This is interesting. I will look at it as a decent solution if I need to revisit the code.
No, I rewrote the accordion with my own directive and moved on. I will try your suggestion when I revisit the code or need to do the same thing again.
@AlexJ liked your solution. Created a mock plunk here.
Hi @ThodorisGreasidis, thanks! It would be useful to show it ;)
1

I was going suggest using a handle in the sort options, but it doesn't seem to help.

$scope.sortableOptions = {
    handle: '.handle'
}

Here's a Plunkr

I'm gonna say the 2 just don't play well together.

You may have better luck with something like http://jimliu.github.io/angular-ui-tree/

3 Comments

Cool demo of angular-ui-tree. The items don't expand (other than for the subtree elements which is not something I need) - so it is not an accordion. I'll wait a bit in the hope of an accordion style solution. Thanks for your input.
I would probably use the sortable because its hard to recreate and just improvise an accordion because it is super simple. plnkr.co/edit/Ydx3Lo?p=preview
I followed the advice and improvised the accordion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.