Skip to content

Commit e627f48

Browse files
[update] the Toolbar.items property (v2.0)
1 parent ca47ff5 commit e627f48

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

docs/api/config/toolbar_items_config.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ items?: [
2121
{
2222
id: string,
2323
label: string,
24-
searchRule?: (card, value, by) => {} // returns a boolean value
24+
searchRule?: (card, value, by) => {
25+
return boolean
26+
}
2527
}, {...}
26-
]
28+
],
29+
resultTemplate?: template(searchResult => {
30+
return "The HTML template of the search result";
31+
})
2732
},
2833
"sort" | {
2934
// sort parameters
@@ -34,8 +39,7 @@ items?: [
3439
by?: string, // by?: ((card: object) => any),
3540
dir?: "asc" | "desc"
3641
}, {...}
37-
]
38-
42+
]
3943
},
4044
"spacer",
4145
"undo",
@@ -57,18 +61,21 @@ In the **items** array you can specify the following parameters:
5761
- `type` - (required) a type of control (*"search"*)
5862
- `options` - (optional) an array of objects, that define the search parameters. For each object (*search option*) you can specify the following parameters:
5963
- `id` - (required) a key of card field, by which the cards will be searched
60-
- `label` - (required) a name of option, used in a dropdown list of the searchbar selector
64+
- `label` - (required) a name of option, used in a dropdown list of the search bar selector
6165
- `searchRule` (optional) - a custom function that allows defining search rules. It takes the following arguments:
6266
- ***card*** - an object of the card data
63-
- ***value*** - a searched value, specified in the searchbar
67+
- ***value*** - a searched value, specified in the search bar
6468
- ***by*** - a key of card field, by which the cards will be searched
69+
- `searchResult` - (optional) a template for displaying the custom search result
6570

6671
~~~jsx
6772
items: [
6873
"search", // default searchbar
6974
// other controls
7075
]
76+
7177
// or
78+
7279
items: [
7380
{ // custom searchbar
7481
type: "search",
@@ -85,7 +92,13 @@ items: [
8592
return date?.toString().includes(value);
8693
}
8794
}
88-
]
95+
],
96+
resultTemplate: kanban.template(searchResult => {
97+
return `<div class="list-item">
98+
<div class="list-item-text">${searchResult.result.label}</div>
99+
${searchResult.result.description ? `<div class="list-item-text item-description">${searchResult.result.description}</div>` : ""}
100+
</div>`
101+
})
89102
},
90103
// other controls
91104
]
@@ -138,7 +151,7 @@ items: [
138151

139152
### Example
140153

141-
~~~jsx {8-16}
154+
~~~jsx {8-24}
142155
const board = new kanban.Kanban("#root", {
143156
columns,
144157
cards
@@ -147,20 +160,30 @@ const board = new kanban.Kanban("#root", {
147160
new kanban.Toolbar("#toolbar", {
148161
api: board.api,
149162
items: [
150-
"search",
163+
{
164+
type: "search",
165+
resultTemplate: kanban.template(searchResult => {
166+
return `<div class="list-item">
167+
<div class="list-item-text">${searchResult.result.label}</div>
168+
${searchResult.result.description ? `<div class="list-item-text item-description">${searchResult.result.description}</div>` : ""}
169+
</div>`
170+
})
171+
},
151172
"spacer",
152173
"sort",
153174
"undo",
154175
"redo",
155176
"addColumn",
156177
"addRow"
157-
],
178+
]
158179
});
159180
~~~
160181

161182
**Change log:**
183+
162184
- The *"Undo"* and *"Redo"* controls were added in v1.3
163185
- The ***items.options[0].label*** parameter of the **sort** control was replaced by the ***items.options[0].text*** parameter in v1.4
186+
- The ***items.searchResult*** parameter of the **"search"** control was added in v2.0
164187

165188
**Related articles:** [Configuration](../../../guides/configuration#toolbar) and [Customization](../../../guides/customization#custom-toolbar)
166189

0 commit comments

Comments
 (0)