最新公告
  • 欢迎访问代码工坊,购买产品可享受在线工单服务!
  • jkanban - 支持拖拽的任务看板JS组件

    jkanban - 支持拖拽的任务看板JS组件

      jKanban允许您在web项目中创建和管理看板!

    安装

          在项目中引入css和js文件即可。

    <link rel="stylesheet" href="path/to/jkanban.min.css">
    <script src="path/to/jkanban.min.js"></script>

    使用方式

          初始化一个实例

    var kanban = new jKanban(options)

          options涉及到的设计项目如下:

    var kanban = new jKanban({
        element          : '',                                           // selector of the kanban container
        gutter           : '15px',                                       // gutter of the board
        widthBoard       : '250px',                                      // width of the board
        responsivePercentage: false,                                    // if it is true I use percentage in the width of the boards and it is not necessary gutter and widthBoard
        dragItems        : true,                                         // if false, all items are not draggable
        boards           : [],                                           // json of boards
        dragBoards       : true,                                         // the boards are draggable, if false only item can be dragged
        itemAddOptions: {
            enabled: false,                                              // add a button to board for easy item creation
            content: '+',                                                // text or html content of the board button   
            class: 'kanban-title-button btn btn-default btn-xs',         // default class of the button
            footer: false                                                // position the button on footer
        },    
        itemHandleOptions: {
            enabled             : false,                                 // if board item handle is enabled or not
            handleClass         : "item_handle",                         // css class for your custom item handle
            customCssHandler    : "drag_handler",                        // when customHandler is undefined, jKanban will use this property to set main handler class
            customCssIconHandler: "drag_handler_icon",                   // when customHandler is undefined, jKanban will use this property to set main icon handler class. If you want, you can use font icon libraries here
            customHandler       : "<span class='item_handle'>+</span> %title% "  // your entirely customized handler. Use %title% to position item title 
                                                                                 // any key's value included in item collection can be replaced with %key%
        },
        click            : function (el) {},                             // callback when any board's item are clicked
        context          : function (el, event) {},                      // callback when any board's item are right clicked
        dragEl           : function (el, source) {},                     // callback when any board's item are dragged
        dragendEl        : function (el) {},                             // callback when any board's item stop drag
        dropEl           : function (el, target, source, sibling) {},    // callback when any board's item drop in a board
        dragBoard        : function (el, source) {},                     // callback when any board stop drag
        dragendBoard     : function (el) {},                             // callback when any board stop drag
        buttonClick      : function(el, boardId) {},                     // callback when the board's button is clicked
        propagationHandlers: [],                                         // the specified callback does not cancel the browser event. possible values: "click", "context"
    })
    

          boards对象的结构如下:

    [
        {
            "id"    : "board-id-1",               // id of the board
            "title" : "Board Title",              // title of the board
            "class" : "class1,class2,...",        // css classes to add at the title
            "dragTo": ['another-board-id',...],   // array of ids of boards where items can be dropped (default: [])
            "item"  : [                           // item of this board
                {
                    "id"    : "item-id-1",        // id of the item
                    "title" : "Item 1"            // title of the item
                    "class" : ["myClass",...]     // array of additional classes
                },
                {
                    "id"    : "item-id-2",
                    "title" : "Item 2"
                }
            ]
        },
        {
            "id"    : "board-id-2",
            "title" : "Board Title 2"
        }
    ]

          在这里要注意,所有的对象ID都应该是唯一的。

    关于自定义属性

          jKanban还支持项目的自定义属性,以使用html数据属性改进应用程序。您可以在以下位置定义它们:

    [
        {
            "id"    : "board-id-1",
            "title" : "Board Title",
            "item"  : [
                {
                    "id"      : "item-id-1",
                    "title"   : "Item 1",
                    "username": "username1"
                },
                {
                    "id"      : "item-id-2",
                    "title"   : "Item 2",
                    "username": "username2"
                }
            ]
        }
    ]

          jKanban将转换为:

    <main class="kanban-drag">
        <div class="kanban-item" data-eid="item-id-1" data-username="username1">Item 1</div>
        <div class="kanban-item" data-eid="item-id-2" data-username="username2">Item 2</div>
    </main>

    API接口

          jKanban提供了简单丰富的API,让你的主板看起来更加个性化!

    Method Name Arguments Description
    addElement boardID, element, position Add element in the board with ID boardIDelement is the standard format. If position is set, inserts at position starting from 0
    addForm boardID, formItem Add formItem as html element into the board with ID boardID
    addBoards boards Add one or more boards in the kanban, boards are in the standard format
    findElement id Find board's item by id
    replaceElement id, element Replace item by id with element JSON standard format
    getParentBoardID id Get board ID of item id passed
    findBoard id Find board by id
    getBoardElements id Get all item of a board
    removeElement id Remove a board's element by id
    removeBoard id Remove a board by id

    项目地址

    源代码:https://github.com/riktar/jkanban/

    项目演示:http://www.riccardotartaglia.it/jkanban/

    发表评论