ui-sortable icon indicating copy to clipboard operation
ui-sortable copied to clipboard

Save the positions on a list created before AngularJS

Open 2buisson opened this issue 12 years ago • 4 comments

The demo for list created by ng-repeat is nice, the ng-model way works to save positions.

But for list created before, like with a PHP, or plain HTML, we can't use ng-model, then how retrieve postions in this case?

Thanks!

2buisson avatar Jul 15 '14 12:07 2buisson

Ui-sortable (and angularjs in general) is not associated with the way the original HTML of a page is generated. It can be a plain HTML file or any server side language/framework (such as php). In order to have the sortings persist a page reload you should:

  • create an ajax page/handler to send the changes (either using the stop() callback or an explicit save button) and save them in the server's database
  • use the browser's local storage, to keep the changes locally

Feel free to provide more info and possibly an example fiddle/pen.

thgreasi avatar Jul 15 '14 15:07 thgreasi

If it can help, here is the way to save positions without ng-model (for exemple if your list was generated without AngularJS):

app.controller('main', function($scope) {
    $scope.sortableOrder = [];
    $scope.sortableOptions = {
        cursor: 'move',
        axis: 'y',
        stop: function(e,ui){
            var $list=ui.item.parent();
            $scope.sortableOrder = $list.sortable('toArray');
            console.log($scope.sortableOrder);
        }
    };
});

Thanks for this module, it work nice!

2buisson avatar Jul 17 '14 00:07 2buisson

:+1: I didn't realize that you just wanted to have the jquery-ui sorting available without an ng-repeat. You probably still have to pass a dummy objet to ng-model so that the custom callbacks can be applied. Does this apply to your case?

thgreasi avatar Jul 17 '14 04:07 thgreasi

I'm quite new to AngularJS, I didn't see what you're trying to explain me :( Do not worry about my question, the way without ng-model finally works. Thanks for support!

2buisson avatar Jul 17 '14 11:07 2buisson