jQuery Kanban: Kanban Events

JavaScript Kanban Widget. The demo demonstrates how to bind to events.

A live JavaScript/jQuery example of jqxKanban, the jQWidgets Kanban component, with its complete source code below. It is one of 10 jqxKanban demos for jQuery.

jqxKanban API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxKanban shows the setup step by step.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxsortable.js, jqxkanban.js, jqxdata.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {
    var fields = [
             { name: "id", type: "string" },
             { name: "status", map: "state", type: "string" },
             { name: "text", map: "label", type: "string" },
             { name: "tags", type: "string" },
             { name: "color", map: "hex", type: "string" },
             { name: "resourceId", type: "number" }
    ];

    var source =
     {
         localData: [
                  { id: "1161", state: "new", label: "Combine Orders", tags: "orders, combine", hex: "#5dc3f0", resourceId: 3 },
                  { id: "1645", state: "work", label: "Change Billing Address", tags: "billing", hex: "#f19b60", resourceId: 1 },
                  { id: "9213", state: "new", label: "One item added to the cart", tags: "cart", hex: "#5dc3f0", resourceId: 3 },
                  { id: "6546", state: "done", label: "Edit Item Price", tags: "price, edit", hex: "#5dc3f0", resourceId: 4 },
                  { id: "9034", state: "new", label: "Login 404 issue", tags: "issue, login", hex: "#6bbd49" }
         ],
         dataType: "array",
         dataFields: fields
     };

    var dataAdapter = new $.jqx.dataAdapter(source);

    var resourcesAdapterFunc = function () {
        var resourcesSource =
        {
            localData: [
                  { id: 0, name: "No name", image: "../../jqwidgets/styles/images/common.png", common: true },
                  { id: 1, name: "Andrew Fuller", image: "../../images/andrew.png" },
                  { id: 2, name: "Janet Leverling", image: "../../images/janet.png" },
                  { id: 3, name: "Steven Buchanan", image: "../../images/steven.png" },
                  { id: 4, name: "Nancy Davolio", image: "../../images/nancy.png" },
                  { id: 5, name: "Michael Buchanan", image: "../../images/Michael.png" },
                  { id: 6, name: "Margaret Buchanan", image: "../../images/margaret.png" },
                  { id: 7, name: "Robert Buchanan", image: "../../images/robert.png" },
                  { id: 8, name: "Laura Buchanan", image: "../../images/Laura.png" },
                  { id: 9, name: "Laura Buchanan", image: "../../images/Anne.png" }
            ],
            dataType: "array",
            dataFields: [
                 { name: "id", type: "number" },
                 { name: "name", type: "string" },
                 { name: "image", type: "string" },
                 { name: "common", type: "boolean" }
            ]
        };

        var resourcesDataAdapter = new $.jqx.dataAdapter(resourcesSource);
        return resourcesDataAdapter;
    }
    
    var log = new Array();
    var updateLog = function () {
        var count = 0;
        var str = "";
        for (var i = log.length - 1; i >= 0; i--) {
            str += log[i] + "<br/>";
            count++;
            if (count > 10)
                break;
        }
        $("#log").html(str);
    }

    $('#kanban').jqxKanban({
        width: getWidth('kanban'),
        resources: resourcesAdapterFunc(),
        source: dataAdapter,
        columns: [
            { text: "Backlog", dataField: "new" },
            { text: "In Progress", dataField: "work" },
            { text: "Done", dataField: "done" }
        ]
    });

    $('#kanban').on('itemMoved', function (event) {
        var args = event.args;
        var itemId = args.itemId;
        var oldParentId = args.oldParentId;
        var newParentId = args.newParentId;
        var itemData = args.itemData;
        var oldColumn = args.oldColumn;
        var newColumn = args.newColumn;

        log.push("itemMoved is raised");
        updateLog();
    });

    $('#kanban').on('columnCollapsed', function (event) {
        var args = event.args;
        var column = args.column;

        log.push("columnCollapsed is raised");
        updateLog();
    });

    $('#kanban').on('columnExpanded', function (event) {
        var args = event.args;
        var column = args.column;

        log.push("columnExpanded is raised");
        updateLog();
    });

    $('#kanban').on('itemAttrClicked', function (event) {
        var args = event.args;
        var itemId = args.itemId;
        var attribute = args.attribute; // template, colorStatus, content, keyword, text, avatar

        log.push("itemAttrClicked is raised");
        updateLog();
    });

    $('#kanban').on('columnAttrClicked', function (event) {
        var args = event.args;
        var column = args.column;
        var cancelToggle = args.cancelToggle; // false by default. Set to true to cancel toggling dynamically.
        var attribute = args.attribute; // title, button

        log.push("columnAttrClicked is raised");
        updateLog();
    });
});

body.html

<div id="kanban"></div>  
<div id="log"></div>

Learn more

More jQuery Kanban demos