Skip to content

Commit e367f95

Browse files
Merge pull request #103 from DHTMLX/sp-SVAR-2592
[add] getCardHeight property documentation
2 parents 65bff65 + e63c5fd commit e367f95

7 files changed

Lines changed: 85 additions & 0 deletions

docs/api/config/js_kanban_cardheight_config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ cardHeight?: number; // px
1919
:::important
2020
If you combine the [`renderType: "lazy"`](api/config/js_kanban_rendertype_config.md) and [`scrollType: "default"`](api/config/js_kanban_scrolltype_config.md) settings, don't forget to specify a static height for cards via the `cardHeight` property. Unless you specify it, the cards will not be displayed.
2121
When you use [`renderType: "lazy"`](api/config/js_kanban_rendertype_config.md) with [`scrollType: "column"`](api/config/js_kanban_scrolltype_config.md), you should also fix the height of cards via the `cardHeight` property. Although a variable height of cards is supported for this type of layout, it may not work in a stable manner with custom card content.
22+
23+
If `cardHeight` is not specified, the widget falls back to an experimental approximation of card heights based on the visible fields declared in [`cardShape`](api/config/js_kanban_cardshape_config.md). With a custom [`cardTemplate`](api/config/js_kanban_cardtemplate_config.md), this approximation does not apply — in that case, either set `cardHeight` explicitly or supply a custom [`getCardHeight`](api/config/js_kanban_getcardheight_config.md) function.
2224
:::
2325

2426
### Example
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
sidebar_label: getCardHeight
3+
title: getCardHeight Config
4+
description: You can learn about the getCardHeight config in the documentation of the DHTMLX JavaScript Kanban library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Kanban.
5+
---
6+
7+
# getCardHeight
8+
9+
### Description
10+
11+
@short: Optional. A function that returns an estimated height of a card
12+
13+
The `getCardHeight` function is used by the widget to estimate card heights when the [`cardHeight`](api/config/js_kanban_cardheight_config.md) property is not set and the board is configured with [`renderType: "lazy"`](api/config/js_kanban_rendertype_config.md) and [`scrollType: "column"`](api/config/js_kanban_scrolltype_config.md). The estimated heights let the widget render the scrollbar correctly before the actual cards are measured in the DOM.
14+
15+
:::info
16+
If you set the [`cardHeight`](api/config/js_kanban_cardheight_config.md) property, the widget uses the fixed height and `getCardHeight` is not called. Setting `cardHeight` is the recommended way to combine `renderType: "lazy"` with `scrollType: "column"`.
17+
:::
18+
19+
### Usage
20+
21+
~~~jsx {}
22+
getCardHeight?: (cardShape: object, card: object, cardWidth: number) => number;
23+
~~~
24+
25+
### Parameters
26+
27+
The callback function takes the following arguments:
28+
29+
- `cardShape` - the configuration object of the card (the [`cardShape`](api/config/js_kanban_cardshape_config.md) property)
30+
- `card` - the data object of the card
31+
- `cardWidth` - the current width of the card in pixels
32+
33+
The function must return a number — the estimated height of the card in pixels.
34+
35+
### Default config
36+
37+
By default, the widget uses a built-in function that approximates card height based on the visible fields declared in [`cardShape`](api/config/js_kanban_cardshape_config.md) and the data stored in the card. This default works for boards that rely on the built-in card layout.
38+
39+
If you provide a custom [`cardTemplate`](api/config/js_kanban_cardtemplate_config.md), the built-in approximation can no longer predict the actual height of the rendered markup. In this case, specify a custom `getCardHeight` function that returns the height of the rendered template, or set a static [`cardHeight`](api/config/js_kanban_cardheight_config.md) instead.
40+
41+
### Example
42+
43+
The example below provides a custom `getCardHeight` function for a board with a custom card template:
44+
45+
~~~jsx {15-22,27}
46+
const cardTemplate = ({ cardFields }) => {
47+
const { label, description } = cardFields;
48+
return `
49+
<div class="custom-card" style="padding:20px">
50+
<div class="custom-label">${label}</div>
51+
<div class="custom-description">${description || ""}</div>
52+
</div>
53+
`;
54+
};
55+
56+
new kanban.Kanban("#root", {
57+
cards,
58+
columns,
59+
renderType: "lazy",
60+
scrollType: "column",
61+
cardTemplate: kanban.template(card => cardTemplate(card)),
62+
getCardHeight: (cardShape, card, cardWidth) => {
63+
// estimate the height of the custom template
64+
let height = 60; // base padding + label line
65+
if (card.description) {
66+
height += Math.ceil(card.description.length / 40) * 18;
67+
}
68+
return height;
69+
},
70+
// other parameters
71+
});
72+
~~~
73+
74+
**Related articles:** [Configuration](guides/configuration.md#rendering-and-scrolling)

docs/api/config/js_kanban_rendertype_config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ renderType?: "default" | "lazy";
2323
:::important
2424
If you combine the `renderType: "lazy"` and [`scrollType: "default"`](api/config/js_kanban_scrolltype_config.md) settings, don't forget to specify a static height for cards via the [`cardHeight`](api/config/js_kanban_cardheight_config.md) property. Unless you specify it, the cards will not be displayed correctly.
2525
When you use `renderType: "lazy"` with [`scrollType: "column"`](api/config/js_kanban_scrolltype_config.md), you should also fix the height of cards via the [`cardHeight`](api/config/js_kanban_cardheight_config.md) property. Although a variable height of cards is supported for this type of layout, it may not work in a stable manner with custom card content.
26+
27+
If `cardHeight` is not set, the widget falls back to an experimental approximation of card heights based on [`cardShape`](api/config/js_kanban_cardshape_config.md). For boards with a custom [`cardTemplate`](api/config/js_kanban_cardtemplate_config.md), supply a custom [`getCardHeight`](api/config/js_kanban_getcardheight_config.md) function instead.
2628
:::
2729

2830
### Default config

docs/api/config/js_kanban_scrolltype_config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ scrollType: "default"
2929
:::important
3030
If you combine the [`renderType: "lazy"`](api/config/js_kanban_rendertype_config.md) and `scrollType: "default"` settings, don't forget to specify a static height for cards via the [`cardHeight`](api/config/js_kanban_cardheight_config.md) property. Unless you specify it, the cards will not be displayed.
3131
When you use [`renderType: "lazy"`](api/config/js_kanban_rendertype_config.md) with `scrollType: "column"`, you should also fix the height of cards via the [`cardHeight`](api/config/js_kanban_cardheight_config.md) property. Although a variable height of cards is supported for this type of layout, it may not work in a stable manner with custom card content.
32+
33+
If `cardHeight` is not set, the widget falls back to an experimental approximation of card heights based on [`cardShape`](api/config/js_kanban_cardshape_config.md). For boards with a custom [`cardTemplate`](api/config/js_kanban_cardtemplate_config.md), supply a custom [`getCardHeight`](api/config/js_kanban_getcardheight_config.md) function instead.
3234
:::
3335

3436
### Example

docs/api/overview/properties_overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ To configure the **Kanban**, refer to the [Configuration](guides/configuration.m
2020
| [](api/config/js_kanban_currentuser_config.md) | @getshort(api/config/js_kanban_currentuser_config.md) |
2121
| [](api/config/js_kanban_editor_config.md) | @getshort(api/config/js_kanban_editor_config.md) |
2222
| [](api/config/js_kanban_editorshape_config.md) | @getshort(api/config/js_kanban_editorshape_config.md) |
23+
| [](api/config/js_kanban_getcardheight_config.md) | @getshort(api/config/js_kanban_getcardheight_config.md) |
2324
| [](api/config/js_kanban_history_config.md) | @getshort(api/config/js_kanban_history_config.md) |
2425
| [](api/config/js_kanban_links_config.md) | @getshort(api/config/js_kanban_links_config.md) |
2526
| [](api/config/js_kanban_locale_config.md) | @getshort(api/config/js_kanban_locale_config.md) |

docs/guides/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ new kanban.Kanban("#root", {
487487

488488
:::important
489489
When you combine `renderType: "lazy"` with any `scrollType`, set a static height for cards through the [`cardHeight`](api/config/js_kanban_cardheight_config.md) property. Without `cardHeight`, lazy rendering does not display cards correctly.
490+
491+
If `cardHeight` is omitted with `renderType: "lazy"` and `scrollType: "column"`, the widget falls back to an experimental approximation of card heights based on the visible fields in [`cardShape`](api/config/js_kanban_cardshape_config.md). For boards that use a custom [`cardTemplate`](api/config/js_kanban_cardtemplate_config.md), the widget cannot predict the rendered height — supply a custom [`getCardHeight(cardShape, card, cardWidth)`](api/config/js_kanban_getcardheight_config.md) function that returns the estimated card height.
490492
:::
491493

492494
## History of changes

sidebars.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ module.exports = {
224224
"api/config/js_kanban_editor_config",
225225
//"api/config/js_kanban_editorautosave_config", REMOVED
226226
"api/config/js_kanban_editorshape_config",
227+
// G
228+
"api/config/js_kanban_getcardheight_config",
227229
// H
228230
"api/config/js_kanban_history_config",
229231
// L

0 commit comments

Comments
 (0)