修改 dhtmlxGantt 以处理多个项目 - Laravel5

Modify dhtmlxGantt to work with multiple projects - Laravel5

我已将 dhtmlxGantt 集成到 Laravel5 项目中,一切都按预期工作。但我想修改它以存储多个项目的图表。为此,我想添加名为 "project_id" 的额外字段并通过过滤器加载数据。

我尝试使用以下代码修改控制器:

$connector->render_links(                                  
    GanttLink::where('user_id', '=', 1)->get(),
    "id", 
    "source,target,type"                
);

$connector->render_table(                                  
    GanttTask::where('user_id', '=', 1)->get(),
    "id",                                                               
    "start_date,duration,text,progress,parent"                      
);

这个解决方案允许我以我想要的方式从数据库加载图表。但它不会将更改保存回数据库。我浏览了 dhtmlxGantt 文档,但没有得到任何解决方案。

我在研究中找到了这些链接,可能会有帮助。

Link 1: Changing values before saving

Link 2: Filtering results based on a parameter

请帮助我以允许在不同图表上工作(加载和编辑)的方式修改我的项目。

终于找到解决办法了。首先,您需要将 project_id 列添加到数据库 table,然后将列添加到连接器配置:

$connector->render_table(new GanttTask(), "id", "start_date,duration,text,progress,parent,project_id");

然后你必须对客户端代码做一些修改。使用类似的东西,

var project_id = "<?php echo $project['id']; ?>";

为了将变量带入<script>..</script> 然后通过添加这两个客户端处理程序来修改您的代码:

gantt.attachEvent("onBeforeTaskDisplay", function (id, task) {
                            if (task.project_id == project_id) {
                                return true;
                            }
                            return false;
                        });

gantt.attachEvent("onBeforeTaskAdd", function (id, task) {
                            task.project_id = project_id;
                        });

第一个处理程序在显示图表之前以您想要的方式过滤结果,第二个处理程序在添加任务之前附加 project_id 属性。现在你有一个可以显示多个项目的 dhtmlxGatt。