riktar / jkanban

Vanilla Javascript plugin for manage kanban boards
https://www.riccardotartaglia.it/jkanban/
Apache License 2.0
1.08k stars 300 forks source link

Get the order of elements on a board #52

Closed akramwahid closed 5 years ago

akramwahid commented 5 years ago

I want to save the order state of elements on the board in the backend db. I know we can listen for call back dragendEl or dragEl in order to detect the item reordering inside a board, how can I get the new order when an item is reordered, I also want to store the order of the Board as well when I enable dragBoards , your help is kindly appreciated

marcosrocha85 commented 5 years ago

Hello @akramwahid , you will have to get the elements and iterate over it. Like:

dropEl: function(el, target, source, sibling) {
    var _target = $(target.parentElement);
    var sorted = [];
    var nodes = jkanban.getBoardElements(_target.data("id"));
    var currentOrder = 0;
    nodes.forEach(function(value, index, array) {
      sorted.push({
        "id": $(value).data("eid"),
        "order": currentOrder++
      })
    });
    $("#working_sort_order").val(JSON.stringify(sorted));
  },

https://jsfiddle.net/marcosrocha85/Lk9t483r/

akramwahid commented 5 years ago

thanks for this, this solved my problem