在Kendo UI Gantt中自动移动后续任务

时间:2017-02-18 23:44:26

标签: kendo-ui kendo-gantt

我正在尝试自动更新telerik甘特图任务

如果我提前1天继续执行任务,那么它应该提前1天自动移动其后续任务。

以下功能会自动移动所有后续任务,但问题是,一旦我刷新页面,我的更改就会丢失,只保存我移动的任务。不要保留使用tasksDataSource.update

进行的更改

完整代码在这里 http://dojo.telerik.com/EYOnu

  function onSave(e) {

                //reinitialize array
                updatedSuccessorsIds = new Array();

                var gantt = e.sender;

                var newStartDate = e.values.end;
                var oldStartDate = e.task.end;

                var diffMs = newStartDate - oldStartDate; // milliseconds between now & old
                var diffMins = Math.round(diffMs / 60000);

                var currentTaskId = e.task.id.toString();

                var dependencies = dependenciesDataSource.successors(currentTaskId);

                $.each(dependencies, function (key, depend) {
                    updateSuccessor(depend.successorId, diffMins);
                });

                //kendoConsole.log("Task saved :: " + e.task.title);
            }

            function onDataBound() {
                //kendoConsole.log("Gantt data bound");
            }

            function onDataBinding() {
                //kendoConsole.log("Gantt data binding");
            }

            function onNavigate(e) {
                //kendoConsole.log(kendo.format("navigate:: view:{0};", e.view));
            }


            function onMoveStart(e) {
                //kendoConsole.log("moveStart");
            }

            function onMove(e) {
                //kendoConsole.log("move");
            }

            function onMoveEnd(e) {


            }

            function updateSuccessor(successortaskId, diffMins) {

                var successortask = tasksDataSource.get(successortaskId);

                if (successortask.summary)
                    return true;//this is parent so ignore its node

                var successortaskStartDate = successortask.start;
                successortaskStartDate.setMinutes(successortaskStartDate.getMinutes() + diffMins);

                var successortaskEndDate = successortask.end;
                successortaskEndDate.setMinutes(successortaskEndDate.getMinutes() + diffMins);


                tasksDataSource.update(successortask,
                                        {
                                            start: successortaskStartDate,
                                            end: successortaskEndDate
                                        });

                //put updated successortask in array so we can use this array to find parent node to update
                updatedSuccessorsIds.push(successortaskId);

                var dependencies = dependenciesDataSource.successors(successortaskId);

                $.each(dependencies, function (key, depend) {
                    updateSuccessor(depend.successorId, diffMins);
                });

            }

1 个答案:

答案 0 :(得分:0)

您需要使用moveEnd事件,因为这会唯一标识要移动的任务(您可能还需要在更改任务持续时间时使用resizeEnd事件)。如果更改实际移动的任务,则需要调用e.preventDefault()以防止调用save方法,该方法将使用e.start和e.end值覆盖您的更改