Questions about gantt.deleteTask()


#1

为什么执行方法:gantt.deleteTask(),出现错误提示:“Task not found
id=xxxx”,这个错误信息是在删除任务并且重新渲染之后出现的

image


#2

Hello Liuy,
Please, post your questions only in English.

If you try to delete a task that doesn’t exist, Gantt can show that error message.

It can be related to Gantt configuration, but it is hard to suggest what might be wrong as I don’t see your code.
Please, reproduce the issue in the snippet, then click on the “Share” button and send me the link:
https://snippet.dhtmlx.com/38ee1b370
Or send me a ready demo with all the necessary Javascript and CSS files so that I can reproduce the issue locally.


#3

Why the execution method: gantt.deleteTask(), an error message appears: “Cannot find the task
id = xxxx”, this error message appeared after deleting the task and re-rendering?


#4

Hello Liuy,
I already answered in the message above. If it is not your use case, please, send me the snippet so that I can reproduce the issue locally.


#5
gantt.config.columns = [
        {
            name: "overdue",
            label: "警示",
            width: 40,
            template: function (obj) {
                // return taskIndicatorLight(obj); // 超期、完成
                return "";
            }
        },
        {
            name: "operation",
            label: "操作",
            width: 50,
            resize: true,
            align: "center",
            template: function (task) {
                // return checkTaskNodeButton(task, getUserCache()); // 配置按钮权限
                return `<button onclick="aaaaaa(this);" id="cancel_${task.id}" identifier="${task.id}"> 取消</button>`;
            }
        },
        {
            name: "wbs",
            label: "WBS",
            min_width: 50,
            width: 50,
            template: gantt.getWBSCode,
            resize: true
        },
        /*{
            name: "text",
            label: "任务",
            editor: {type: "text", map_to: "text"},
            tree: true,
            align: "left",
            resize: true,
            width: 200,
            template: function (task) {
                if (task.text != null) {
                    return task.text;
                } else {
                    return "";
                }
            }
        },
        {
            name: "matter_name",
            label: "事项",
            editor: selectMatterParam,
            align: "left",
            resize: true,
            width: 100,
            template: function (task) {
                if (task.matter_name != null) {
                    return task.matter_name;
                } else {
                    return "";
                }
            }
        },
        {
            name: "launch_user_name",
            label: "发起人",
            editor: selectUserByAunchUserIdParam,
            align: "left",
            resize: true,
            width: 100,
            template: function (task) {
                if (task.launch_user_name != null) {
                    return task.launch_user_name;
                }
                return "";
            }
        },
        {
            name: "execute_user_name",
            label: "执行人",
            editor: selectUserByExecuteUserParam,
            align: "left",
            resize: true,
            width: 100,
            template: function (task) {
                if (task.execute_user_name != null) {
                    return task.execute_user_name;
                }
                return "";
            }
        },
        {
            name: "start_date",
            label: "开始时间",
            editor: {
                type: "date", map_to: "start_date"
            },
            align: "left",
            resize: true,
            width: 100
        },
        {
            name: "end_date",
            label: "结束时间",
            editor: {
                type: "date", map_to: "end_date"
            },
            align: "left",
            resize: true,
            width: 100
        },
        {
            name: "duration",
            label: "计划天",
            editor: {type: "number", map_to: "duration"},
            align: "center",
            resize: true,
            width: 50
        },
        {
            name: "deferredDays",
            label: "延期天",
            align: "center",
            resize: true,
            width: 50,
            hidden: "hidden",
            template: function (task) {
                return checkDeferredDays(task);
            }
        }*/
    ]; // 定义字段
    gantt.config.details_on_dblclick = false; // 双击打开预设的窗口
    gantt.config.autoscroll = false; // 定义自动滚动
    gantt.config.sort = true; // 甘特图排序
    gantt.config.drag_progress = false; // 禁止调整甘特图进度
    gantt.config.drag_links = true; // 允许连线
    gantt.config.auto_scheduling_move_projects = false; // 是否定义将项目节点移动
    gantt.config.drag_lightbox = false; // 可以通过标题拖动灯箱
    gantt.config.drag_move = false; // 允许用户移动任务节点
    gantt.config.drag_resize = true; // 允许用户推拽来调整时间长短
    gantt.config.grid_width = 300; // 定义网格宽度
    gantt.config.autofit = false; // 自适应宽度(此处不能设置为true,否则样式错乱)
    gantt.config.autosize_min_width = 100; // 自适应宽度最小
    gantt.config.xml_date = "%Y-%m-%d %H:%i:%s";// 日期格式规范文档:https://docs.dhtmlx.com/gantt/desktop__date_format.html
    gantt.config.scale_height = 20 * 2;
    gantt.config.task_height = 35;
    gantt.init("plan_scheduling_gantt");
    gantt.load(serverFileName + "/ptm/task/main/TaskMainController/queryPlanScheduleDataVo?token=" + token_project + "&projectId=" + projectId /*+ "&userOrgId=" + 9*/);
    gantt.createDataProcessor({ //  创建一个新的dataProcessor实例并将其附加到甘特图 {url:string, mode:string}指定发送数据的预定义模式之一的对象、文档:https://docs.dhtmlx.com/gantt/api__gantt_createdataprocessor.html
        url: serverFileName + "/ptm/task/main/TaskMainController/queryPlanScheduleDataVo?token=" + token_project + "&projectId=" + projectId /*+ "&userOrgId=" + 9*/,
        mode: "POST" // "JSON" | "REST-JSON" | "JSON" | "POST" | "GET"
    });

Hello, I still can’t solve the problem of task not found id = xxxx. This is my test code.

The code called by the delete button is as follows

function aaaaaa(object) {
var taskId = $(object).attr("identifier");
gantt.deleteTask(taskId);}

#6

Hello Liuy,
Thank you for sending your Gantt configuration. I was able to reproduce the issue.
Looks like the issue occurs because the task is deleted before the onTaskClick event fires.

You can return false in the onTaskClick event when you click on that button:
http://snippet.dhtmlx.com/5/5112d1af8
Or you can delete tasks after a small timeout:
http://snippet.dhtmlx.com/5/31f9f1a21