jkanban icon indicating copy to clipboard operation
jkanban copied to clipboard

addElement API function doesn't insert at desired position

Open bairog opened this issue 3 years ago • 5 comments

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.

bairog avatar Oct 13 '21 10:10 bairog

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

xscode-auto-reply[bot] avatar Oct 13 '21 10:10 xscode-auto-reply[bot]

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?

marcosrocha85 avatar Oct 13 '21 20:10 marcosrocha85

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)?

bairog avatar Oct 14 '21 07:10 bairog

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. 🙁

marcosrocha85 avatar Oct 15 '21 16:10 marcosrocha85

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.

bairog avatar Oct 18 '21 05:10 bairog