|
| 1 | +--- |
| 2 | +title: Collapsing Gantt Nodes in UI for ASP.NET AJAX |
| 3 | +description: Learn how to collapse nodes in the Gantt component in UI for ASP.NET AJAX using client-side methods. |
| 4 | +type: how-to |
| 5 | +page_title: How to Collapse Gantt Nodes in UI for ASP.NET AJAX |
| 6 | +meta_title: How to Collapse Gantt Nodes in UI for ASP.NET AJAX |
| 7 | +slug: gantt-collapsing-nodes |
| 8 | +tags: aspnet-ajax,gantt,client-side,collapse-nodes |
| 9 | +res_type: kb |
| 10 | +ticketid: 1695987 |
| 11 | +--- |
| 12 | + |
| 13 | +## Environment |
| 14 | + |
| 15 | +<table> |
| 16 | +<tbody> |
| 17 | +<tr> |
| 18 | +<td>Product</td> |
| 19 | +<td>UI for ASP.NET AJAX Gantt</td> |
| 20 | +</tr> |
| 21 | +<tr> |
| 22 | +<td>Version</td> |
| 23 | +<td>All</td> |
| 24 | +</tr> |
| 25 | +</tbody> |
| 26 | +</table> |
| 27 | + |
| 28 | +## Description |
| 29 | + |
| 30 | +I want to collapse all nodes in the [Gantt](https://docs.telerik.com/devtools/aspnet-ajax/controls/gantt/overview) component for UI for ASP.NET AJAX using a button. The provided client-side code does not work, and there are no JavaScript errors. I need to know the correct approach for accomplishing this functionality. |
| 31 | + |
| 32 | +This knowledge base article also answers the following questions: |
| 33 | +- How to collapse Gantt nodes using client-side methods? |
| 34 | + |
| 35 | +## Solution |
| 36 | + |
| 37 | +The UI for ASP.NET AJAX Gantt does not provide a public client-side API for directly collapsing or expanding tasks. However, you can use the following workaround to achieve this functionality. |
| 38 | + |
| 39 | +````ASP.NET |
| 40 | +<telerik:RadButton ID="btnCollapseNodes" runat="server" Text="Collapse Nodes" AutoPostBack="false" OnClientClicked="onClientClicked" /> |
| 41 | +```` |
| 42 | + |
| 43 | +The provided JavaScript function references private properties, which is not recommended. Use the public API instead: |
| 44 | + |
| 45 | +````JavaScript |
| 46 | +function onClientClicked(sender, args) { |
| 47 | + let gantt = $find("<%= RadGantt1.ClientID %>"); // Replace RadGantt1 with your Gantt's ClientID |
| 48 | + let tasks = gantt.get_tasks(); // Get all tasks in the Gantt |
| 49 | + |
| 50 | + for (let i = 0; i < tasks.get_count(); i++) { |
| 51 | + let task = tasks.getTask(i); |
| 52 | + |
| 53 | + if (task._data.hasChildren) { // Check if the task has child nodes |
| 54 | + task.set_expanded(false); // Set the expanded state to false |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + gantt.repaint(); // Refresh the Gantt to reflect the changes |
| 59 | +} |
| 60 | +```` |
| 61 | + |
| 62 | +## See Also |
| 63 | + |
| 64 | +- [UI for ASP.NET AJAX Gantt Overview](https://docs.telerik.com/devtools/aspnet-ajax/controls/gantt/overview) |
| 65 | +- [RadButton Documentation](https://docs.telerik.com/devtools/aspnet-ajax/controls/button/overview) |
0 commit comments