support icon indicating copy to clipboard operation
support copied to clipboard

Gantt State is not persisting columns added using `addNew` column

Open taauntik opened this issue 2 years ago • 2 comments

Forum post

Hi,

When a new column is added using "New Column", reloading the gantt is not recreating columns added. Attached sample here.

Reproducible in gantt/examples/state

Steps:

Run attached sample add any column using New Column Make some dummy changes to script and apply changes. Observe Newly added columns are not restored.

import { AjaxHelper, AsyncHelper, StringHelper, StateProvider, Toast, Gantt } from '../../build/gantt.module.js?474872';
import shared from '../_shared/shared.module.js?474872';

 

const stateId = 'mainGantt';

function launch() {
    const gantt = new Gantt({
        appendTo          : 'container',
        dependencyIdField : 'sequenceNumber',

    // The key used to automatically save this widget's state in the page's state provider
    stateId,

    // If start/end dates are not provided, they'd be inferred from the project and will override dates restored from
    // the state
    startDate : new Date(2019, 0, 13),
    endDate   : new Date(2019, 2, 24),

    features : {
        filter : true
    },

    project : {
        autoLoad  : true,
        transport : {
            load : {
                url : '../_datasets/launch-saas.json'
            }
        }
    },

    tbar : [
        {
            type  : 'checkbox',
            ref   : 'autoSaveCheckbox',
            label : 'Auto save',
            value : true,
            onChange({ checked }) {
                gantt.stateId = checked ? stateId : null;
            }
        },
        {
            type    : 'button',
            ref     : 'resetButton',
            color   : 'b-red',
            icon    : 'b-fa b-fa-times',
            text    : 'Reset to default',
            tooltip : 'Resets application to the default state',
            onAction() {
                gantt.resetDefaultState();

                Toast.show('Default state restored');
            }
        }
    ],

    columns : [
        // To persist column state it is better to explicitly specify an id
        { id : 'name', type : 'name', width : 250 },
        { id : 'startDate', type : 'startdate', width : 150 },
        { id : 'duration', type : 'duration', width : 150 },
        { id : 'predecessors', type : 'predecessor', width : 150 },
        { id : 'effort', type : 'effort', width : 150, hidden: true },
        { id : 'addnew', type : 'addnew', width : 150 }
    ],

    // Custom task content, display task name on child tasks
    taskRenderer({ taskRecord }) {
        if (taskRecord.isLeaf && !taskRecord.isMilestone) {
            return StringHelper.encodeHtml(taskRecord.name);
        }
    }
});
}



StateProvider.setup('local');
    launch();

taauntik avatar Mar 25 '24 11:03 taauntik

test / progress pushed to branch 8876-state

matsbryntse avatar Mar 25 '24 23:03 matsbryntse

hey, any update on this issue?

vmelooo avatar Oct 02 '24 23:10 vmelooo

@vloax Implemented, awaiting review/merge

matsbryntse avatar Dec 02 '24 23:12 matsbryntse