Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert new record ( model ) in TreePanel?

Tags:

tree

store

extjs4

I use TreeStore & TreePanel. I need to insert new node in my Tree , how to this?

I have TreeStore component who following 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 have defined Task Model (it is what I want to insert) with blank 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 new record when event itemdlclick is fired:

I have tested that but it doesn't 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);          
}

Thanks a lot :) !

like image 347
Vincent Guesné Avatar asked May 24 '11 15:05

Vincent Guesné


1 Answers

I think you asked the similar question here!

There is no insert method for tree panel. You will have to get hold of the tree's root node to modify the tree. In your case, you might have to do the following:

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

For other tree manipulation methods, refer the API documentation of NodeInterface.

like image 182
Abdel Raoof Olakara Avatar answered Sep 21 '22 13:09

Abdel Raoof Olakara