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

addElement API function doesn't insert at desired position #147

Open
bairog opened this issue Oct 13, 2021 · 5 comments
Open

addElement API function doesn't insert at desired position #147

bairog opened this issue Oct 13, 2021 · 5 comments

Comments

@bairog
Copy link

bairog commented Oct 13, 2021

Hello.
According to docs addElement API function adds element in the board with ID boardID, element is the standard format. If position is set, inserts at position starting from 0.
I've tried the following code but element still insterted at the very bottom:

KanbanTest.addElement(sourceBoardId, {
        id: itemId,
        title: itemText
    }, 1);

123
Sample application - https://jsfiddle.net/bairog/wtha2d3f/79/

Is that a bug or there is a mistake in my code?
Thank you in advance.

@xscode-auto-reply
Copy link

Thanks for opening a new issue. The team has been notified and will review it as soon as possible.
For urgent issues and priority support, visit https://xscode.com/riktar/jkanban

@marcosrocha85
Copy link
Contributor

I tried to reproduce your issue, but it worked fine locally. I noticed that https://cdn.jsdelivr.net/npm/[email protected]/dist/jkanban.js is using "appendChild" instead of "insertBefore". Maybe that version is not properly compiled. @riktar can you confirm that latest dist files are correct?

@bairog
Copy link
Author

bairog commented Oct 14, 2021

BTW. To return draggedItem to the original position on sourceBoard (if user clicked Cancel drag button) I need to determine draggedItem index on the sourceBoard. For today I use the following code:

function boardDragEl(jKanban, el, source) {
    var sourceBoardId = jKanban.getParentBoardID(el.dataset.eid);
    var sourceBoardItems = Array.from(jKanban.getBoardElements(sourceBoardId));
    sourceBoardDraggedItemIndex = sourceBoardItems.indexOf(el);
}

Is that piece of code fine or may there are some optimizations/shortcuts (I'm not so familiar with jKanban API yet)?

@marcosrocha85
Copy link
Contributor

As jKanban uses and manipulates DOM elements. You can use:

dragEl: function(el, source) {
    var sourceBoardId = source.parentElement.dataset.id;
    var sourceBoardItems = Array.from(jKanban.getBoardElements(sourceBoardId));
    sourceBoardDraggedItemIndex = sourceBoardItems.indexOf(el);
}

But for instance that is the best way to get an element position from a board. 🙁

@bairog bairog changed the title addElement API function doesn't intsert at desired position addElement API function doesn't insert at desired position Oct 18, 2021
@bairog
Copy link
Author

bairog commented Oct 18, 2021

I tried to reproduce your issue, but it worked fine locally. I noticed that https://cdn.jsdelivr.net/npm/[email protected]/dist/jkanban.js is using "appendChild" instead of "insertBefore". Maybe that version is not properly compiled.

Just tested with dist\jkanban.min.css and dist\jkanban.min.js files from this repo and they work as expected. Looks like to jsdelivr files really incorrect. @riktar looks like jsdelivr files reupload is needed.. Thank you in advance.

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

No branches or pull requests

2 participants