Skip to content

Commit db40b80

Browse files
authored
Merge pull request #63 from DHTMLX/add-responsive-ui-to-gantt-3166
[add] a guide on adding responsive ui into gantt
2 parents 27f8810 + 196f38e commit db40b80

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

docs/guides/how-to.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,4 +983,3 @@ gantt.event(gantt.$root, "click", function(e){
983983
}
984984
});
985985
~~~
986-

docs/guides/responsive-ui.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: "Making Gantt Responsive"
3+
sidebar_label: "Making Gantt Responsive"
4+
---
5+
6+
# Making Gantt Responsive
7+
8+
Working with Gantt on smartphones can be uncomfortable due to their small screens that don't allow displaying all the data at once. However, Gantt can be configured to adapt its layout to different screen sizes, making it usable on both desktop and mobile devices.
9+
10+
If you specify Gantt sizes in percent values (for example, `width: 100%; height: 100%`), it will adjust to the available container size. However, by default, each grid column has a minimum width defined by the [`min_column_width`](api/config/min_column_width.md) and [`min_grid_column_width`](api/config/min_grid_column_width.md) parameters. If the container becomes smaller than the total minimum column width, the grid stops shrinking. This may give the impression that Gantt is not responsive. The following sections describe the ways to address this and make Gantt truly responsive.
11+
12+
### Adjusting minimum column width
13+
14+
One approach is to decrease the values of [`min_column_width`](api/config/min_column_width.md) and [`min_grid_column_width`](api/config/min_grid_column_width.md). This allows Gantt to shrink further as the container gets smaller, providing a responsive-like behavior:
15+
16+
~~~jsx
17+
gantt.config.min_column_width = 30;
18+
gantt.config.min_grid_column_width = 30;
19+
~~~
20+
21+
**Related sample** [Gantt. Responsive container](https://snippet.dhtmlx.com/kjibqqbb)
22+
23+
### Adjusting the layout for small screens
24+
25+
Another approach is to switch the Gantt layout based on the available width. When there is enough space, the full layout with both the grid and the timeline is displayed. On narrow screens, either the grid or the timeline is shown instead to make better use of the limited space.
26+
27+
This can be implemented using the [`onGanttRender`](api/event/onganttrender.md) event. The event handler checks the width of the Gantt container, the current [layout](api/config/layout.md) configuration and updates Gantt layout accordingly.
28+
29+
**Related sample** [Gantt. Responsive layout: dynamically hide/show the grid depending on the screen width](https://snippet.dhtmlx.com/w4nwk5wf)

sidebars.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ module.exports = {
3838
items: [
3939
"guides/installation",
4040
"guides/cdn-links-list",
41-
"guides/initializing-gantt-chart"
42-
43-
41+
"guides/initializing-gantt-chart",
42+
"guides/responsive-ui"
4443
]
4544
},
4645

0 commit comments

Comments
 (0)