Skip to content
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

dragSortPredicate does not seem to work properly #553

Open
RAIbrahim360 opened this issue May 5, 2023 · 2 comments
Open

dragSortPredicate does not seem to work properly #553

RAIbrahim360 opened this issue May 5, 2023 · 2 comments

Comments

@RAIbrahim360
Copy link

https://codepen.io/Ibishka/pen/YzJYLZV

Recording.2023-05-05.223433.mp4
@RAIbrahim360
Copy link
Author

RAIbrahim360 commented May 5, 2023

let dragStartItems;

const grid = new Muuri(".grid", {
  dragEnabled: true,
  layout: {
    fillGaps: true
  },
  dragSortPredicate: (item) => {
    const result = Muuri.ItemDrag.defaultSortPredicate(item);

    if (result) {
      if (result.index === 6) {
        return false;
      }
    }

    return Muuri.ItemDrag.defaultSortPredicate(item);
  }
})
  .on("dragStart", () => {
    dragStartItems = grid.getItems();
  })
  .on("dragReleaseEnd", (item) => {
     // You must use dragReleaseEnd instead of dragEnd, to sort correctly
    // You must sort, because sometimes return incorrect order
    const sortedGridItems = grid.getItems().sort((a, b) => {
      const aPos = a.getPosition();
      const bPos = b.getPosition();

      return aPos.top - bPos.top || aPos.left - bPos.left;
    });
    const itemIndex = sortedGridItems.indexOf(item);
    const prevItem = dragStartItems[itemIndex].getElement();

    if (Number(prevItem.dataset.index) !== 6) {
      return;
    }

    const itemPrevIndex = dragStartItems.indexOf(item);
    grid.move(item, itemPrevIndex, { layout: "instant" });
  });

for those, who want solution. But this should fixed from core

@RAIbrahim360
Copy link
Author

@niklasramo Any progress on that?

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

No branches or pull requests

1 participant