This is a migrated thread and some comments may be shown as answers.

Gantt disable/hide some resources in resources window

7 Answers 107 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 22 Jan 2020, 09:09 AM

Hello,
I need to customize the resources window (when adding/removing assigned persons).
The idea is, that a specific person has permission to populate some tasks with some persons.
For example, the leader of a team can add only people of his team, to tasks where the parent task is assigned to his team.
I can do that permissions logic, I just need to know how to disable/hide some resources when resources window is opened.

Thank you.

7 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 22 Jan 2020, 04:14 PM

Hello Igor,

The Gantt by default does not allow manipulation of the resource grid but you can access it and hide rows conditionally by overriding some of its internal functions: 

var original_createResourceEditor = kendo.ui.Gantt.prototype._createResourceEditor
kendo.ui.Gantt.prototype._createResourceEditor = function (container, options) {
    original_createResourceEditor.call(this, container, options);
    var resourceEditorGrid = this._resourceEditor.grid;

    resourceEditorGrid.element.find(".k-grid-content tr")
        .each(function (index, rowElement) {
            var rowDataItem = resourceEditorGrid.dataItem(rowElement);
            if (rowDataItem.name == "Thomas Hardy") {
                $telerik.$(rowElement).hide();
            }
        })
}

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Igor
Top achievements
Rank 1
answered on 23 Jan 2020, 08:39 AM

Hello Peter,

Thank you for the answer, unfortunately, I was not able to use this code successfully.

I put the code to window.onload function. The function _createResourceEditor is not triggered.
Is it possible, that this code is for Kendo and not for ASP.NET ajax?

0
Accepted
Peter Milchev
Telerik team
answered on 27 Jan 2020, 03:11 PM

Hello Igor,

The provided script should be placed after the RadScriptManager and should not be in window.onload or any other event handler.

<script>
    var original_createResourceEditor = kendo.ui.Gantt.prototype._createResourceEditor;
    kendo.ui.Gantt.prototype._createResourceEditor = function (container, options) {
        original_createResourceEditor.call(this, container, options);
        var resourceEditorGrid = this._resourceEditor.grid;

        resourceEditorGrid.element.find(".k-grid-content tr")
            .each(function (index, rowElement) {
                var rowDataItem = resourceEditorGrid.dataItem(rowElement);
                
                // your custom logic here...
                if (rowDataItem.name == "Thomas Hardy") {
                    $telerik.$(rowElement).hide();
                }
            })
    }
</script> 

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Igor
Top achievements
Rank 1
answered on 28 Jan 2020, 12:47 PM

Now it is working.

Thank you.

0
Igor
Top achievements
Rank 1
answered on 29 Jan 2020, 02:39 PM

Hello, 

this solution has another bug, when something is changed in Resources table (New resource assigned, etc.),

all rows, hidden also are visible again.

How can I fox this please?

Thank you

0
Accepted
Peter Milchev
Telerik team
answered on 03 Feb 2020, 08:46 AM

Hello Igor,

The grid is rebinding when checking/unchecking a resource, so the same functionality needs to be executed in the dataBound event:

var original_createResourceEditor = kendo.ui.Gantt.prototype._createResourceEditor
kendo.ui.Gantt.prototype._createResourceEditor = function (container, options) {
    original_createResourceEditor.call(this, container, options);
    var resourceEditorGrid = this._resourceEditor.grid;
    hideResource();

    function hideResource() {
        resourceEditorGrid.element.find(".k-grid-content tr")
            .each(function (index, rowElement) {
                var rowDataItem = resourceEditorGrid.dataItem(rowElement);
                if (rowDataItem.name == "Thomas Hardy") {
                    $telerik.$(rowElement).hide();
                }
            })
    }

    resourceEditorGrid.bind("dataBound", hideResource);
}

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Igor
Top achievements
Rank 1
answered on 03 Feb 2020, 10:18 AM

Hello Peter,

Now it is ok.

Thank you.

Tags
Gantt
Asked by
Igor
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Igor
Top achievements
Rank 1
Share this question
or