items
描述
可选。一个数组,包含排列在看板工具栏上的控件。
用法
items?: [
"search" | {
// 搜索参数
type: "search",
options?: [
{
id: string,
label: string,
searchRule?: (card, value, by) => {
return boolean
}
}, {...}
],
resultTemplate?: template(searchResult => {
return "搜索结果的 HTML 模板";
})
},
"sort" | {
// 排序参数
type: "sort",
options?: [
{
text: string,
by?: string, // by?: ((card: object) => any),
dir?: "asc" | "desc"
}, {...}
]
},
"spacer",
"undo",
"redo",
"addColumn",
"addRow",
custom_control // 字符串或函数
];
参数
在 items 数组中,可以包含以下参数:
信息
添加 默认搜索栏,只需使用字符串 "search"
。
配置 自定义搜索栏,需提供包含以下参数的对象:
type
- (必需)指定控件类型("search")options
- (可选)定义搜索参数的数组。每个对象(搜索选项)可以包含:id
- (必需)用于搜索的卡片字段键label
- (必需)搜索栏下拉中显示的选项名称searchRule
(可选)- 自定义函数,用于定义搜索规则。接收参数:- card - 卡片数据对象
- value - 搜索输入值
- by - 用于搜索的卡片字段键
searchResult
- (可选)自定义搜索结果显示的模板
items: [
"search", // 默认搜索栏
// 其他控件
]
// 或者
items: [
{ // 自定义搜索栏
type: "search",
options: [
{
id: "label",
label: "按标签"
},
{
id: "start_date",
label: "按日期",
searchRule: (card, value, by) => {
const date = card[by];
return date?.toString().includes(value);
}
}
],
resultTemplate: kanban.template(searchResult => {
return `<div className="list-item">
<div className="list-item-text">${searchResult.result.label}</div>
${searchResult.result.description ? `<div className="list-item-text item-description">${searchResult.result.description}</div>` : ""}
</div>`
})
},
// 其他控件
]