Skip to content

Added svIndex attribute #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/angular-sortable-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
var isGrid = false;
var onSort = $parse($attrs.svOnSort);

// ----- fix for multiple page list (when pagination is made on front-end);
// ----- index is recalculated depending on page
var startIndex = 0;
$attrs.$observe('svIndex', function (value) {
startIndex = parseInt(value) > 0 ? parseInt(value) : 0;
});
// -------------------------------------------------------------------

// ----- hack due to https://github.com/angular/angular.js/issues/8044
$attrs.svOnStart = $attrs.$$element[0].attributes['sv-on-start'];
$attrs.svOnStart = $attrs.svOnStart && $attrs.svOnStart.value;
Expand Down Expand Up @@ -212,6 +220,8 @@
this.$drop = function(originatingPart, index, options){
if(!$placeholder) return;

index += startIndex;

if(options.revert){
var placeholderRect = $placeholder[0].getBoundingClientRect();
var helperRect = $helper[0].getBoundingClientRect();
Expand Down Expand Up @@ -258,8 +268,8 @@
if($target){
$target.element.removeClass('sv-candidate');
var spliced = originatingPart.model(originatingPart.scope).splice(index, 1);
var targetIndex = $target.targetIndex;
if($target.view === originatingPart && $target.targetIndex > index)
var targetIndex = $target.targetIndex + startIndex;
if($target.view === originatingPart && $target.targetIndex + startIndex > index)
targetIndex--;
if($target.after)
targetIndex++;
Expand Down