Angular集成dhtmlx Gantt:按数组属性分组任务的问题
Angular中dhtmlx Gantt按数组类型属性分组的问题
我在Angular项目中使用dhtmlx Gantt,需要实现按值为数组类型的任务属性分组,效果要和官方示例中按owner分组一致。但当前实现存在以下问题:
- 仅数组含单个值的任务能被分组,多值数组的任务没有对应分组
- 未显示默认分组,无分组的任务以树形结构展示
时间线组件分组功能代码
setGroupingResources(gantt: any) { _.forOwn(this.groupingResources, (data: [], key: String) => { gantt.serverList(key, data); }); } groupView (gantt: any) { gantt.$groupMode = !gantt.$groupMode; if (!this.groupByProperty) { gantt.groupBy(false); return; } gantt.eachTask((task: any) => { if(!task[this.groupByProperty]) task[this.groupByProperty] = 0 if (task[this.groupByProperty] instanceof Array) { var values = task[this.groupByProperty]; for (var i = 0; i < values.length; i++) { task.original_id = task.id; gantt.updateTask(task.id) var clone = gantt.copy(task); clone.original_id = clone.id clone.id = gantt.uid(); clone[this.groupByProperty] = values[i]; clone.$temporary = true; gantt.addTask(clone); var clone = gantt.getTask(clone.id); clone.parent = clone.$rendered_parent; } } }) gantt.groupBy({ groups: gantt.serverList(this.groupByProperty) , relation_property: this.groupByProperty, group_id: 'id', group_text: 'name', delimiter: ", ", save_tree_structure: true }); } ngOnChanges(changes: SimpleChanges) { if (!this._gantt) return; this.groupingResources = changes['groupingResources'] && changes['groupingResources'].currentValue || this.groupingResources; this.groupByProperty = changes['groupByProperty'] && changes['groupByProperty'].currentValue || this.groupByProperty; this._gantt.clearAll(); if (changes['groupingResources']) this.setGroupingResources(this._gantt); this.groupView(this._gantt) this._gantt.parse({ data: this.data, links: this.links }); this._gantt.render(); }
示例数据
[ { id: 1, name: "task #1", goal: [1, 2], }, { id: 2, name: "task #2", goal: [1], }, { id: 3, name: "task #3", goal: [], }, { id: 4, name: "task #4", goal: [2], }, { id: 5, name: "task #5", goal: [5, 6], }, ];
内容的提问来源于stack exchange,提问作者Wafia Mustafa
相关产品推荐
相关产品推荐

