23 days to give it a try before you buy! Download now. The best deals on licenses are coming soon Download now. The best deals on licenses are coming soon

Kanban DND Events, JavaScript Programming Example of Kanban DND Events

JavaScript Programming Example of Kanban DND Events

In Webix Kanban, you can drag-n-drop items with tasks from one column to another. It's also possible to forbid all DND operations. Check out a free coding sample of Kanban DND Events below. Feel free to take advantage of it for your project.

JS Code

function onBeforeDrag(dragContext){
  webix.message("Drag has been started");
  return true
};

function onBeforeDragIn(dragContext,e,list){
  // item id
  var item = this.getItem(dragContext.start);

  // if we move an item from one list to another
  if(dragContext.from != dragContext.to){
    var statusFrom = dragContext.from.config.status;
    var statusTo = dragContext.to.config.status;
    var statusIndex = {"new":0,"work":1, "test": 2, "done":3};
    var diff = Math.abs(statusIndex[statusFrom] - statusIndex[statusTo]);
    if(diff>1){
      return false;
    }
  }
  return true;
};

function onAfterDrop(dragContext,e,list){
  // item id
  var item =this.getItem(dragContext.start);

  // if we move an item from one list to another
  if(dragContext.from != dragContext.to){
    var status = dragContext.to.config.status;
    // show a message with new status and order
    webix.message("Item '"+item.text+"' was moved into '"+status+"' column to the "+item.$index +" position");
  }
  else
    webix.message("Item '"+item.text+"' was moved to the "+item.$index +" position");
};

webix.ready(function(){
    webix.CustomScroll.init();

  webix.ui({
    type:"space",
    rows:[
      {  view:"label", label:"You can move tasks only between neighbouring columns"},
      {
        view:"kanban",
        id:"myBoard",
        type:"wide",
        on:{
          onListBeforeDrag: onBeforeDrag,
          onListBeforeDragIn: onBeforeDragIn,
          onListAfterDrop: onAfterDrop
        },
        cols:[
          { header:"Backlog",
           body:{ view:"kanbanlist", status:"new"}
          },
          { header:"In Progress",
           body:{ view:"kanbanlist", status:"work"}
          },
          { header:"Testing",
           body:{ view:"kanbanlist", status:"test"}
          },
          { header:"Done",
           body:{ view:"kanbanlist", status:"done"}
          }
        ],
        tags:tags_set,
        users:users_set,
        data:full_task_set
      }
    ]
  });
});

HTML Code

<link rel="stylesheet" type="text/css" href="https://docs.webix.com/samples/63_kanban/common/style.css">

<script>
 var path =  "https://docs.webix.com/samples/63_kanban/";
 var users_set = [
	{id:1, value:"Rick Lopes", image:path+"common/imgs/1.jpg"},
	{id:2, value:"Martin Farrell", image:path+"common/imgs/2.jpg"},
	{id:3, value:"Douglass Moore", image:path+"common/imgs/3.jpg"},
	{id:4, value:"Eric Doe", image:path+"common/imgs/4.jpg"},
	{id:5, value:"Sophi Elliman", image:path+"common/imgs/5.jpg"},
	{id:6, value:"Anna O'Neal"},
	{id:7, value:"Marcus Storm", image:path+"common/imgs/7.jpg"},
	{id:8, value:"Nick Branson", image:path+"common/imgs/8.jpg"},
	{id:9, value:"CC", image:path+"common/imgs/9.jpg"}
 ];

 var tags_set = [
	{id:1, value:"webix"},
	{id:2, value:"jet"},
	{id:3, value:"easy"},
	{id:4, value:"hard"},
	{id:5, value:"kanban"},
	{id:6, value:"docs"},
 ];
 var full_task_set = [
	{ id:1, status:"new", text:"Test new authentification service", tags:[1,2,3] },
	{ id:2, status:"work", user_id: 5, text:"Performance tests", tags:[1] },
	{ id:3, status:"work", user_id: 6, text:"Kanban tutorial", tags:[2] },
	{ id:4, status:"work", user_id: 3, text:"SpreadSheet NodeJS", tags:[3] },
	{ id:5, status:"test", user_id: 9, text:"Portlets view", tags:[4,2] },
	{ id:6, status:"new", user_id: 7, text:"Form Builder", tags:[4,6] },
	{ id:7, status:"test", text:"Code Snippet", tags:[1,2,3] },
	{ id:8, status:"work", user_id: 1, text:"Backend integration", tags:[5] },
	{ id:9, status:"work", user_id: 2, text:"Drag-n-drop with shifting cards", tags:[5] },
	{ id:10, status:"work", user_id: 4, text:"Webix Jet 2.0", tags:[4] },
	{ id:11, status:"test", user_id: 9, text:"Chat app interface", tags:[4,2] },
	{ id:12, status:"done", user_id: 8, text:"Material skin", tags:[4,6] }
 ];
</script>