ANovokmet/svelte-gantt

Cannot use updateRow or updateRows method to add add rows with children

paul121 opened this issue · 3 comments

When using updateRow or updateRows to add rows with child rows it seems that these are not correctly added.. I get a row label of undefined and then when adding tasks for these rows via updateTasks I get the following error:

TypeError: Cannot read properties of undefined (reading 'y')

It seems that the y value might not be set for these new rows?

Adding child rows does work when using gantt.$set({rows}). I also tested adding these rows all as parent/top-level rows via updateRow and updateRows and they worked fine, all tasks were added correctly with updateTasks.

I see that the updateRow and updateRows methods call rowFactory.createRow(model, null) where null is the Y value:

export function updateRow(model) {
const row = rowFactory.createRow(model, null);
rowStore.upsert(row);
}
export function updateRows(rowModels) {
const rows = rowModels.map(model => rowFactory.createRow(model, null));
rowStore.upsertAll(rows);

But the initRows logic is different calls rowFactory.createRows(rows):

function initRows(rowsData) {
//Bug: Running twice on change options
const rows = rowFactory.createRows(rowsData);
rowStore.addAll(rows);
}

It seems that rowFactory.createRows is the only method that ever calls rowFactory.createChildRows:

createRows(rows: RowModel[]) {
const ctx = { y: 0, result: [] };
this.createChildRows(rows, ctx);
return ctx.result;
}
createChildRows(

Thank you. This is about to be fixed in v4.4.1