用了jQuery的gantt插件加了一个函数
JSGantt.makeInOneRow = function(groups){ for(var i = 0; i < groups.length; i++){ var group = groups[i]; if(group && group.length > 1){ var barWrapper = document.getElementById("childgrid_" + group[0]); for(var j = 1; j < group.length; j++){ var bar = document.getElementById("bardiv_" + group[j]); barWrapper.appendChild(bar); //remove useless row var wrapper = document.getElementById("childgrid_" + group[j]); wrapper.parentNode.removeChild(wrapper); } } } }
使用时
g.AddTaskItem(new JSGantt.TaskItem(11, 'Define Variables', '7/20/2008', '8/14/2008', 'ff00ff', 'http://help.com', 0, 'Brian', 60, 0, 1, 1, '','Caption 1')); g.AddTaskItem(new JSGantt.TaskItem(12, 'Define Variables', '8/20/2008', '8/24/2008', 'ff00ff', 'http://help.com', 0, 'Brian', 60, 0, 1, 1, '','Caption 1')); g.AddTaskItem(new JSGantt.TaskItem(21, 'Define Variables', '7/25/2008', '8/5/2008', 'ff00ff', 'http://help.com', 0, 'Brian', 70, 0, 2, 1, '','Caption 1')); g.AddTaskItem(new JSGantt.TaskItem(22, 'Define Variables', '8/9/2008', '8/20/2008', 'ff00ff', 'http://help.com', 0, 'Brian', 70, 0, 2, 1, '','Caption 1')); g.AddTaskItem(new JSGantt.TaskItem(31, 'Define Variables', '7/22/2008', '8/10/2008', 'ff00ff', 'http://help.com', 0, 'Brian', 30, 0, 3, 1, '','Caption 1')); g.Draw(); g.DrawDependencies(); JSGantt.makeInOneRow([[11, 12],[21, 22],[31]]);
完整例子在附件里。