📜  jQWidgets jqxKanban 模板属性(1)

📅  最后修改于: 2023-12-03 15:32:18.332000             🧑  作者: Mango

jQWidgets jqxKanban 模板属性介绍

jqxKanban 是 jQWidgets 框架下的一个组件,能够快速地创建看板式的任务管理界面。本文将介绍 jqxKanban 的模板属性,希望对程序员们有所帮助。

基础用法

首先,我们需要引入 jQWidgets 的样式和脚本文件:

<link rel="stylesheet" href="https://cdn.jqwidgets.com/jquery-widgets/4.5.3/jqwidgets/styles/jqx.base.css">
<script src="https://cdn.jqwidgets.com/jquery-widgets/4.5.3/jqwidgets/jqxcore.js"></script>
<script src="https://cdn.jqwidgets.com/jquery-widgets/4.5.3/jqwidgets/jqxkanban.js"></script>

接着,我们需要创建一个 <div> 标签作为容器,然后初始化 jqxKanban:

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

<script>
    $(document).ready(function () {
        // 初始化数据
        var source = {
            dataType: "json",
            dataFields: [
                { name: "id", type: "string" },
                { name: "status", map: "state", type: "string" },
                { name: "text", type: "string" },
                { name: "content", type: "string" },
                { name: "tags", type: "string" },
                { name: "color", type: "string" }
            ],
            id: "id",
            url: "./data.json"
        };

        // 初始化 jqxKanban
        $("#kanban").jqxKanban({
            width: '100%',
            height: 600,
            source: new $.jqx.dataAdapter(source),
            columns: [
                { text: "To Do", dataField: "new", maxItems: 7 },
                { text: "In Progress", dataField: "work", maxItems: 7 },
                { text: "Done", dataField: "done", maxItems: 7 }
            ]
        });
    });
</script>
模板属性
  1. itemTemplate

    用于定义每个任务卡片的样式,可以使用 HTML 代码或者函数。HTML 代码可以使用模板字符串的方式指定,例如:

    itemTemplate: `<div class="jqx-kanban-item" style="border-left-color:{color}">
                        <div class="jqx-kanban-item-color-status"></div>
                        <div style="display:none;" class="jqx-kanban-item-avatar"></div>
                        <div class="jqx-kanban-item-text">{text}</div>
                    </div>`
    

    如果想要使用函数,可以使用如下的方法:

    itemTemplate: function (item) {
        return `<div class="jqx-kanban-item" style="border-left-color:${item.color}">
                    <div class="jqx-kanban-item-color-status"></div>
                    <div style="display:none;" class="jqx-kanban-item-avatar"></div>
                    <div class="jqx-kanban-item-text">${item.text}</div>
                </div>`;
    }
    

    在模板字符串中,可以使用占位符 {} 来引用任务项中的属性。例如,{text} 表示任务项的文本内容。

  2. columnTemplate

    用于定义每个列的头部样式,同样可以使用 HTML 代码或函数进行定义。

    columnTemplate: `<div class="jqx-kanban-column-header">
                         <div class="jqx-kanban-column-header-text">{text}</div>
                         <div class="jqx-kanban-column-header-count">{itemsCount}</div>
                     </div>`
    
  3. swimlaneHeaderTemplate

    用于定义每个泳道的头部样式,同样可以使用 HTML 代码或函数进行定义。

    swimlaneHeaderTemplate: `<div class="jqx-kanban-swimlane-header">{text}</div>`
    
  4. swimlaneTemplate

    用于定义每个泳道的样式,同样可以使用 HTML 代码或函数进行定义。

    swimlaneTemplate: `<div class="jqx-kanban-swimlane">{items}</div>`
    

    在其中,我们可以使用占位符 {items} 来表示当前泳道中的所有任务项。

总结

在本文中,我们介绍了 jqxKanban 的模板属性,通过设置这些属性,我们可以自定义任务卡片、列头、泳道等的样式,从而让管理界面更加美观、易用。