Skip to content

Commit a097b90

Browse files
Merge pull request #53 from mlakatkou/GS-3268
[update] autosize article
2 parents f87dda5 + cda7916 commit a097b90

1 file changed

Lines changed: 34 additions & 35 deletions

File tree

docs/api/config/autosize.md

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,70 +24,69 @@ gantt.init("gantt_here");
2424

2525
### Details
2626

27-
The 'autosize' config defines whether the gantt will fit data inside the sizes of container where it's initialized showing inner scrollbars,
28-
or modify the sizes of container in order to show all data without inner scrolls:
27+
The `autosize` config defines whether the Gantt will fit data inside the size of the container where it's initialized and show inner scrollbars,
28+
or modify the size of the container in order to show all data without inner scrolls:
2929

30-
- [a sample with sizes of gantt div defined in css ](https://snippet.dhtmlx.com/5/b4d4d1b80) - inner scrollbars are active if necessary
31-
- [a sample with sizes of gantt div calculated by a component](https://snippet.dhtmlx.com/5/c278b3859) - inner scrollbars are disabled
30+
- [a sample with sizes of Gantt div defined in CSS](https://snippet.dhtmlx.com/2m48u5oz) - inner scrollbars are active if necessary
31+
- [a sample with sizes of Gantt div calculated by a component](https://snippet.dhtmlx.com/syzmiqwt) - inner scrollbars are disabled
3232

33-
In case gantt should fit a certain area on a page, the size of gantt container must be managed manually:
33+
In case Gantt should fit a certain area on a page, the size of the Gantt container must be managed manually:
3434

35-
- autosizing should be disabled
36-
- width/height of a div should be calculated either by html layout if some ready solution for responsive layouts is used, or manually by code.
35+
- autosizing should be disabled
36+
- width/height of a div should be calculated either by HTML layout if some ready solution for responsive layouts is used, or manually by code
3737

38-
## Scrolling to hidden elements
38+
## Scrolling to hidden elements
3939

40-
In the default mode, Gantt is scrolled automatically when you use the [showTask](api/method/showtask.md) or [showDate](api/method/showdate.md) method.
41-
But, when **autosize** is enabled, Gantt increases the size of its container to show itself on the page instead of showing the hidden element.
40+
In the default mode, Gantt is scrolled automatically when you use the [`showTask()`](api/method/showtask.md) or [`showDate()`](api/method/showdate.md) method.
41+
But, when `autosize` is enabled, Gantt increases the size of its container to show itself on the page instead of showing the hidden element.
4242

4343
There is no any universal way to escape the problem because the page can also include other elements except for Gantt, and some of the elements also need to be scrolled. Therefore, this problem should be solved depending on the page/application configuration.
4444

4545
In a *simple* configuration, Gantt may be located before or after some elements in your application. And it can work correctly if you scroll the page.
4646

47-
In a *complex* configuration, the Gantt container can be placed into other containers which can also be placed in some other containers.
48-
In this case, you need to manually scroll only the elements you need.
47+
In a *complex* configuration, the Gantt container can be placed into other containers which can also be placed in some other containers.
48+
In this case, you need to manually scroll only the elements you need.
4949

50-
One of the ways to make the page to be scrolled to the necessary element is use the **element.scrollIntoView** method:
50+
One of the ways to make the page scroll to the necessary element is to use the `element.scrollIntoView()` method:
5151

5252
~~~js
53-
var attr = gantt.config.task_attribute;
54-
var timelineElement = document.querySelector(".gantt_task_line["+attr+"='"+id+"']");
55-
if(timelineElement)
56-
timelineElement.scrollIntoView({block:"center"});
53+
const taskAttribute = gantt.config.task_attribute;
54+
const timelineElement = document.querySelector(`.gantt_task_line[${taskAttribute}='${id}']`);
55+
56+
timelineElement?.scrollIntoView({ block: "center" });
5757
~~~
5858

5959
where id is the task ID you need to show.
6060

61-
Another way is to modify the [showTask](api/method/showtask.md) or [showDate](api/method/showdate.md) method of Gantt:
61+
Another way is to modify the [`showTask()`](api/method/showtask.md) or [`showDate()`](api/method/showdate.md) method of Gantt:
6262

6363
~~~js
64-
var showTask = gantt.showTask;
65-
66-
gantt.showTask = function(id){
67-
showTask.apply(this, [id]);
68-
var attr = gantt.config.task_attribute;
69-
var timelineElement = document.querySelector(".gantt_task_line["+attr+"='"+id+"']");
70-
if(timelineElement)
71-
timelineElement.scrollIntoView({block:"center"});
64+
const defaultShowTask = gantt.showTask;
65+
66+
gantt.showTask = function(id) {
67+
defaultShowTask.apply(this, [id]);
68+
const taskAttribute = gantt.config.task_attribute;
69+
const timelineElement = document.querySelector(`.gantt_task_line[${taskAttribute}='${id}']`);
70+
71+
timelineElement?.scrollIntoView({ block: "center" });
7272
};
7373
~~~
7474

7575
or create a custom function to show the task:
7676

7777
~~~js
78-
function showTask(id){
79-
gantt.showTask(id);
80-
var attr = gantt.config.task_attribute;
81-
var timelineElement = document.querySelector(".gantt_task_line["+attr+"='"+id+"']");
82-
if(timelineElement)
83-
timelineElement.scrollIntoView({block:"center"});
84-
}
78+
const showTask = (id) => {
79+
gantt.showTask(id);
80+
const taskAttribute = gantt.config.task_attribute;
81+
const timelineElement = document.querySelector(`.gantt_task_line[${taskAttribute}='${id}']`);
82+
83+
timelineElement?.scrollIntoView({ block: "center" });
84+
};
8585
~~~
8686

8787
:::note
88-
sample: [Scrolling to the specified element](https://snippet.dhtmlx.com/or73u6a5)
88+
Sample: [Scrolling to the specified element](https://snippet.dhtmlx.com/or73u6a5)
8989
:::
9090

9191
### Related API
9292
- [autosize_min_width](api/config/autosize_min_width.md)
93-

0 commit comments

Comments
 (0)