|
| 1 | +--- |
| 2 | +title: Select Task On Click of Expand or Collapse Icon |
| 3 | +description: An example on how to implement a functionality to select the task when clicking on the expand or collapse icon. |
| 4 | +type: how-to |
| 5 | +page_title: Implement Task Selection on Click of Expand or Collapse icon | Kendo UI Gantt for jQuery |
| 6 | +slug: select-gantt-task-on-expand-collapse |
| 7 | +tags: kendo, kendoui, gantt, select, expand, collapse, task, icon, click |
| 8 | +ticketid: 1483656 |
| 9 | +res_type: kb |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | + <tr> |
| 16 | + <td>Product</td> |
| 17 | + <td>Progress Kendo UI Gantt</td> |
| 18 | + </tr> |
| 19 | + <tr> |
| 20 | + <td>Product Version</td> |
| 21 | + <td>2020.3.1021</td> |
| 22 | + </tr> |
| 23 | +</table> |
| 24 | + |
| 25 | + |
| 26 | +## Description |
| 27 | + |
| 28 | +I want to be able to click on the expand/collapse icon of the parent task and select the current row. |
| 29 | + |
| 30 | +## Solution |
| 31 | + |
| 32 | +1. [Attach an event handler](/api/javascript/data/model/methods/bind) to the [expand](/api/javascript/ui/treelist/methods/expand) and [collapse](/api/javascript/ui/treelist/methods/collapse) events of the built-in TreeList. |
| 33 | +1. Get a reference to the current row. |
| 34 | +1. Use the Gantt [select method](https://docs.telerik.com/kendo-ui/api/javascript/ui/gantt/methods/select) to select the current row. |
| 35 | + |
| 36 | +``` |
| 37 | + gantt.list.bind('expand',function(e){ |
| 38 | + gantt.select(this.element.find('[data-uid="'+e.model.uid+'"]')); |
| 39 | + }); |
| 40 | +
|
| 41 | + gantt.list.bind('collapse',function(e){ |
| 42 | + gantt.select(this.element.find('[data-uid="'+e.model.uid+'"]')); |
| 43 | + }); |
| 44 | +``` |
| 45 | + |
| 46 | +## Example |
| 47 | + |
| 48 | +```dojo |
| 49 | +
|
| 50 | + <div id="gantt"></div> |
| 51 | +
|
| 52 | + <script> |
| 53 | + $(document).ready(function() { |
| 54 | + var serviceRoot = "https://demos.telerik.com/kendo-ui/service"; |
| 55 | + var tasksDataSource = new kendo.data.GanttDataSource({ |
| 56 | + transport: { |
| 57 | + read: { |
| 58 | + url: serviceRoot + "/GanttTasks", |
| 59 | + dataType: "jsonp" |
| 60 | + }, |
| 61 | + update: { |
| 62 | + url: serviceRoot + "/GanttTasks/Update", |
| 63 | + dataType: "jsonp" |
| 64 | + }, |
| 65 | + destroy: { |
| 66 | + url: serviceRoot + "/GanttTasks/Destroy", |
| 67 | + dataType: "jsonp" |
| 68 | + }, |
| 69 | + create: { |
| 70 | + url: serviceRoot + "/GanttTasks/Create", |
| 71 | + dataType: "jsonp" |
| 72 | + }, |
| 73 | + parameterMap: function(options, operation) { |
| 74 | + if (operation !== "read") { |
| 75 | + return { models: kendo.stringify(options.models || [options]) }; |
| 76 | + } |
| 77 | + } |
| 78 | + }, |
| 79 | + schema: { |
| 80 | + model: { |
| 81 | + id: "id", |
| 82 | + fields: { |
| 83 | + id: { from: "ID", type: "number" }, |
| 84 | + orderId: { from: "OrderID", type: "number", validation: { required: true } }, |
| 85 | + parentId: { from: "ParentID", type: "number", defaultValue: null, validation: { required: true } }, |
| 86 | + start: { from: "Start", type: "date" }, |
| 87 | + end: { from: "End", type: "date" }, |
| 88 | + title: { from: "Title", defaultValue: "", type: "string" }, |
| 89 | + percentComplete: { from: "PercentComplete", type: "number" }, |
| 90 | + summary: { from: "Summary", type: "boolean" }, |
| 91 | + expanded: { from: "Expanded", type: "boolean", defaultValue: true } |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + }); |
| 96 | +
|
| 97 | + var dependenciesDataSource = new kendo.data.GanttDependencyDataSource({ |
| 98 | + transport: { |
| 99 | + read: { |
| 100 | + url: serviceRoot + "/GanttDependencies", |
| 101 | + dataType: "jsonp" |
| 102 | + }, |
| 103 | + update: { |
| 104 | + url: serviceRoot + "/GanttDependencies/Update", |
| 105 | + dataType: "jsonp" |
| 106 | + }, |
| 107 | + destroy: { |
| 108 | + url: serviceRoot + "/GanttDependencies/Destroy", |
| 109 | + dataType: "jsonp" |
| 110 | + }, |
| 111 | + create: { |
| 112 | + url: serviceRoot + "/GanttDependencies/Create", |
| 113 | + dataType: "jsonp" |
| 114 | + }, |
| 115 | + parameterMap: function(options, operation) { |
| 116 | + if (operation !== "read") { |
| 117 | + return { models: kendo.stringify(options.models || [options]) }; |
| 118 | + } |
| 119 | + } |
| 120 | + }, |
| 121 | + schema: { |
| 122 | + model: { |
| 123 | + id: "id", |
| 124 | + fields: { |
| 125 | + id: { from: "ID", type: "number" }, |
| 126 | + predecessorId: { from: "PredecessorID", type: "number" }, |
| 127 | + successorId: { from: "SuccessorID", type: "number" }, |
| 128 | + type: { from: "Type", type: "number" } |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + }); |
| 133 | +
|
| 134 | + var gantt = $("#gantt").kendoGantt({ |
| 135 | + dataSource: tasksDataSource, |
| 136 | + dependencies: dependenciesDataSource, |
| 137 | + views: [ |
| 138 | + "day", |
| 139 | + { type: "week", selected: true }, |
| 140 | + "month" |
| 141 | + ], |
| 142 | + columns: [ |
| 143 | + { field: "id", title: "ID", width: 60 }, |
| 144 | + { field: "title", title: "Title", editable: true, sortable: true }, |
| 145 | + { field: "start", title: "Start Time", format: "{0:MM/dd/yyyy}", width: 100, editable: true, sortable: true }, |
| 146 | + { field: "end", title: "End Time", format: "{0:MM/dd/yyyy}", width: 100, editable: true, sortable: true } |
| 147 | + ], |
| 148 | + height: 700, |
| 149 | + showWorkHours: false, |
| 150 | + showWorkDays: false, |
| 151 | + snap: false |
| 152 | + }).data("kendoGantt"); |
| 153 | +
|
| 154 | +
|
| 155 | + gantt.list.bind('expand',function(e){ |
| 156 | + gantt.select(this.element.find('[data-uid="'+e.model.uid+'"]')); |
| 157 | + }); |
| 158 | +
|
| 159 | + gantt.list.bind('collapse',function(e){ |
| 160 | + gantt.select(this.element.find('[data-uid="'+e.model.uid+'"]')); |
| 161 | + }); |
| 162 | + }); |
| 163 | + </script> |
| 164 | +``` |
0 commit comments