How to insert a new record (model) in a TreePanel?

I use TreeStoreand TreePanel. I need to insert a new node into my tree, how to do this?

I have a component TreeStorethat after config:

var monPrestore = Ext.create('Ext.data.TreeStore', {
    folderSort : true,
    model : 'Task',
    proxy : {
        model : 'Task',
        appendId: true,
        type : 'ajax',
        url : '/intranet-timesheet2-tasks-extjs/getJSON.tcl',
        reader : {
            type : 'json'
        },
        writer : {
            type : 'json'
        },
    }

I defined a task model (this is what I want to insert) with an empty value:

Ext.define('Task', {
    extend : 'Ext.data.Model',
    fields : [
        {
            name : 'task',
            type: 'string'
        },
        {
            name : 'material',
            type: 'string'
        },
        {
            name : 'cc',
            type: 'string'
        },
        {
            name : 'start_date',
            type: 'string'
        },
        {
            name : 'short_desc',
            type: 'string'
        },
        {
            name : 'id',
            type: 'string'
        }
    ]
});

I want to insert a new entry when the event fires itemdlclick:

I tested this, but it does not work:

itemdblclick: function(view, model, htmlitem, index, e) {
    var task = {
        task: 't0',
        material: 'm0',
        cc: 'c0',
        start_date: '12',
        short_desc: 'sht',
        id: '120',
        leaf: true
    };

    monPretree.insert(4,task);          
}

Thank you so much:)!

+5
source share
1 answer

I think you asked a similar question here !

There is no insertion method for the tree panel. You will need to get the root of the node tree in order to modify the tree. In your case, you may need the following:

var rootNode = monPretree.getRootNode();
rootNode.insertChild(4,task); 

API NodeInterface.

+9

All Articles