Save the positions on a list created before AngularJS
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!
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.
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!
:+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?
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!