why can’t i add an element to this gantt.$task_scale.appendChild(scaleLine);
scaleLine is just a div that i created with createElement
here is my hook
const createLineWithClass = (id: string) => {
const line = document.createElement('div');
line.className = 'today-line';
line.setAttribute('id', id);
return line;
};
const clean = (ref: RefObject<Nullable<HTMLDivElement>>) => {
if (ref.current?.parentNode) {
ref.current.parentNode.removeChild(ref.current);
ref.current = null;
}
};
export const useFixedLine = (gantt: GanttStatic, fixedDate = new Date()) => {
const lineRef = useRef<Nullable<HTMLDivElement>>(null);
const lineRefScale = useRef<Nullable<HTMLDivElement>>(null);
useEffect(() => {
if (!gantt?.$task_data || !gantt?.$container || !gantt.$task_scale) return;
const gridLine = createLineWithClass('gridLine');
const scaleLine = createLineWithClass('scaleLine');
lineRef.current = gridLine;
lineRefScale.current = scaleLine;
gantt.$task_data.appendChild(gridLine); // Work
gantt.$task_scale.appendChild(scaleLine); //doesn't work
const update = () => {
if (!lineRef.current || !lineRefScale.current) return;
const fixed = gantt.date.date_part(fixedDate);
const left = gantt.posFromDate(fixed);
const scrollLeft = gantt.$container.scrollLeft;
lineRef.current.style.left = `${left - scrollLeft}px`;
lineRef.current.style.top = `0`;
lineRef.current.style.width = `2px`;
lineRef.current.style.height = `${gantt.$task_bg.scrollHeight}px`;
lineRefScale.current.style.left = `${left - scrollLeft}px`;
lineRefScale.current.style.top = `0`;
lineRefScale.current.style.width = `2px`;
lineRefScale.current.style.height = `${gantt.config.scale_height}px`;
};
update();
gantt.attachEvent('onGanttRender', update);
return () => {
clean(lineRef);
clean(lineRefScale);
};
}, [gantt]);
};
i need this line